john kanyora

john kanyora

  • NA
  • 242
  • 46.3k

how to use a loop with radiobutton to retrieve data

Feb 23 2018 2:27 AM
Hi, kindly requesting to be assisted on how to use radiobuttons to retrieve data from a table in the database. i have three radiobuttons, such that once the user selects one the data is retrieved from a table to the gridview and if the other is selected the same happens.
 
this is my .aspx code containing the radiobutton.
  1. <asp:RadioButtonList ID="Radiobuttonlist1" OnCheckedChange="Radiobuttonlist1_CheckedChange" runat="server">  
  2. <asp:ListItem Text="Patients" Value="Patients"></asp:ListItem>  
  3. <asp:ListItem Text="Suppliers" Value="Suppliers"></asp:ListItem>  
  4. <asp:ListItem Text="Employees" Value="Employees"></asp:ListItem>  
  5. </asp:RadioButtonList>  
  6. <asp:GridView ID="GridView1" runat="server" />  
this is my code behind which i have just created only for one radiobutton..kindly help on how to implement the loop.
  1. protected void radioButton1_CheckedChanged(Object sender, EventArgs e)  
  2. {  
  3. string connect = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;  
  4. SqlConnection conn = new SqlConnection(connect);  
  5.   
  6. conn.Open();  
  7. SqlCommand cmd = new SqlCommand("select PatientName,PatientCellPhone from CustomerInformation where SampleColumn='"+radiobutton1.value.Text + "';",conn);  
  8. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  9. DataSet ds = new DataSet();  
  10. da.Fill(ds);  
  11. conn.Close();  
  12. GridView1.DataSource = ds;  
  13. GridView1.DataBind();  
  14. }

Answers (7)