title: ListView with Drop-downlist & check box
body: <p>I am developing an asp.net web application in which I have Listview with drop-down &amp; check-box option.</p>
  
  <p>All the items checked needs to inserted into SQL Table. </p>
  
  <p>However , before inserting to database , there needs to validation on drop-down to make sure drop-down has selected value (Selected index should not be 0 ) if checkbox is checked</p>
  
  <p>Kindly Help me for the same
  Below is my aspx</p>
  
  <pre><code>&lt;asp:ListView ID="myListView" runat="server" OnItemDataBound="myListView_ItemDataBound" OnItemCommand="myListView_ItemCommand"   &gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label runat="server" id="lblmemberid" Text='&lt;%# Bind("memberid") %&gt;'&gt;&gt;&lt;/asp:Label&gt;
              &lt;asp:Label runat="server" id="lblName" Text='&lt;%# Bind("name") %&gt;'&gt;&gt;&lt;/asp:Label&gt;
              &lt;asp:Label runat="server" id="lblAge" Text='&lt;%# Bind("Age") %&gt;'&gt;&gt;&lt;/asp:Label&gt;
              &lt;asp:DropDownList runat="server" ID="ddlStatus"   AutoPostBack="true" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged" &gt;&lt;/asp:DropDownList&gt;
              &lt;asp:CheckBox runat="server" CommandName="Select" OnCommand="myListView_ItemCommand" AutoPostBack="true" ID="chkSelect" /&gt;
              &lt;br /&gt;
  
          &lt;/ItemTemplate&gt;
  
      &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>Below is my code</p>
  
  <pre><code>public void bindData()
          {
              SqlConnection con = new SqlConnection();
              con.ConnectionString = "Persist Security Info=False;User ID=sa;Initial Catalog=Subh_Vivah;Data Source=.;password=adarkar";
              //con.Open();
              string memberid = Request.QueryString["memberid"];
              string sqlQuery = "SELECT TOP 10  Name , memberid , age FROM Member_Details  ";
              SqlDataAdapter ada = new SqlDataAdapter(sqlQuery, con);
              DataSet ds = new DataSet();
              ada.Fill(ds);
              if (ds.Tables[0].Rows.Count != 0)
              {
  
                  myListView.DataSource = ds;
                  myListView.DataBind();
              }
  
          }
  
          protected void myListView_ItemDataBound(object sender, ListViewItemEventArgs e)
          {
              List&lt;string&gt; status = new List&lt;string&gt;();
              status.Add("SELECT");
              status.Add("YES");
              status.Add("NO");
  
              DropDownList ddl = e.Item.FindControl("ddlStatus") as DropDownList;
              ddl.DataSource = status;
              ddl.DataBind();
              ddl.SelectedIndexChanged += new EventHandler(ddlStatus_SelectedIndexChanged);
  
          }
  
          protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
          {
              CheckBox chk = (CheckBox)myListView.FindControl("chkSelect");
  
  
  
              DropDownList ddl = (DropDownList)sender;
              if (ddl.SelectedValue == "SELECT")
              {
                  chk.Checked = false;
                  chk.Enabled = false; 
              }
  
  
          }
  </code></pre>