0
Answer

How to select only one radio button based on gridview row selection using c#.net

sathish kumar

sathish kumar

12y
2k
1
 
hi friends....


I have two radio buttons Male and Female.
i m storing those data in database using Insert query.

Now i have to select particular radio button based on gridview row.



 <asp:Label ID="Label6" runat="server" Text="Patient Name"></asp:Label>
                &nbsp;<asp:Label ID="Label26" runat="server" ForeColor="Red" Text="(*)"></asp:Label>
                &nbsp;&nbsp;
                <asp:TextBox ID="txtPatientName" runat="server" Width="300px" ForeColor="#000099"></asp:TextBox>
         
<asp:RadioButton ID="rbMale" runat="server" GroupName="b" Text="Male"
                AutoPostBack="True" oncheckedchanged="rbMale_CheckedChanged" />
            &nbsp;&nbsp;
            <asp:RadioButton ID="rbFemale" runat="server" GroupName="b" Text="Female"
                AutoPostBack="True" oncheckedchanged="rbFemale_CheckedChanged" />



 <table class="GridViewStyle">
                     
             <tr>
            <td class="style3">
             <asp:Panel ID="scrollableGridArea" runat="server" ScrollBars ="Auto"
                      style="overflow:scroll; height: 290px; width:900px" Height="240px"
                      Width="787px">
                  <asp:GridView ID="gvNewRegistration" runat="server" AllowPaging="True"
                      AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlNewRegistration"
                      EmptyDataText="No Records found !!" ForeColor="#333333" GridLines="None"
                      Height="289px" ondatabound="gvNewRegistration_DataBound"
                      onprerender="gvNewRegistration_PreRender"
                      onrowcommand="gvNewRegistration_RowCommand"
                      onselectedindexchanged="gvNewRegistration_SelectedIndexChanged"
                      ShowFooter="True" Width="414px">
                      <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                      <Columns>
                          <asp:CommandField ShowSelectButton="true" />
                          <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                          <asp:BoundField DataField="Patient_Name" HeaderText="Patient Name"
                              SortExpression="Patient_Name" />
                        
                          <asp:BoundField DataField="Sex" HeaderText="Sex" SortExpression="Sex" />
                         
                      </Columns>
                      <FooterStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                      <PagerStyle CssClass="PagerStyle" />
                      <SelectedRowStyle CssClass="SelectedRowStyle" />
                      <HeaderStyle CssClass="HeaderStyle" />
                      <EditRowStyle CssClass="EditRowStyle" />
                      <AlternatingRowStyle CssClass="AltRowStyle" />
                      <PagerSettings FirstPageText="First" LastPageText="Last"
                          Mode="NextPreviousFirstLast" NextPageText="Next" PageButtonCount="5"
                          Position="Top" PreviousPageText="Previous" />
                  </asp:GridView>
                   <asp:SqlDataSource ID="SqlNewRegistration" runat="server"
                      ConnectionString="<%$ ConnectionStrings:CMC %>"
                      SelectCommand="SELECT [Title],[Patient_Name],[Street],[City],[State],[Country],[Zip_Code],[Phone_1],[Phone_2],[Mobile_Number],[Ward],[ISDischarged],[MR_Number],[HospitalNo],[Ward_ID],[Patient_Type],[Sex],[Date_Admitted],[tinYear],[tinMonth],[tinDays],[BillType],[RefBy],[CorporateCode],[PackageCode],[InsuranceCode],[VisitCode] FROM [registration_details] ORDER BY [MR_Number]"


 protected void gvNewRegistration_RowCommand(object sender, GridViewCommandEventArgs e)
    {
     
           
        if (e.CommandName == "Select")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow gvRow = gvNewRegistration.Rows[index];
            cmdAdd.Enabled = false;
            cmdDelete.Enabled = true;
            cmdModify.Enabled = true;
            cmdCancel.Enabled = true;


            string CName;
            string Pname;
            string Iname;

            if (e.CommandSource == "Male")
            {
              int rowIndex = int.Parse(e.CommandArgument.ToString());
           
                rbMale.Checked = true;
            }

            else if (e.CommandSource == "Female")
            {
                int rowIndex = int.Parse(e.CommandArgument.ToString());
                rbFemale.Checked = true;
            }
            else
            {
                rbMale.Checked = false;
                rbFemale.Checked = false;

            }

            if (e.CommandSource == "IP")
            {
                int rowIndex = int.Parse(e.CommandArgument.ToString());
                rbIP.Checked = true;
            }

            else if (e.CommandSource == "OP")
            {
                int rowIndex = int.Parse(e.CommandArgument.ToString());
                rbOP.Checked = true;
            }

            else if (e.CommandSource == "Direct")
            {
                int rowIndex = int.Parse(e.CommandArgument.ToString());
                rbDirect.Checked = true;
            }
            else
            {
                rbIP.Checked = false;
                rbOP.Checked = false;
                rbDirect.Checked = false;
            }
}
 protected void Display_Record(string strCode)
    {

        string strSQL;
        string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(dbConn);
        sqlConn.Open();
       // strSQL = "SELECT [Patient_Type],[HospitalNo],[MR_Number],[Title],[Sex],[BillType],[Date_Admitted],[Street],[City],[State],[Country],[Zip_Code],[Phone_1],[Phone_2],[Mobile_Number],[tinYear],[tinMonth],[tinDays],[CorporateCode],[PackageCode],[InsuranceCode],[Ward],[RefBy] FROM [registration_details] Where [Patient_Name]='" + strCode + "'";

        strSQL = "select  Title,Patient_Name,Street,City,State,Country,Zip_Code,Phone_1,Phone_2,Mobile_Number,MR_Number,Ward,Patient_Type,Sex,Date_Admitted,tinMonth,tinYear,tinDays,BillType,RefBy,CorporateCode,PackageCode,InsuranceCode FROM [registration_details] Where [HospitalNo]='" + strCode + "'";
        SqlCommand cmdRegistration = new SqlCommand(strSQL, sqlConn);
        SqlDataReader drRegistration = cmdRegistration.ExecuteReader();
        while (drRegistration.Read())
        {
            txtPatientName.Text = drRegistration[1].ToString();
                                  
             }

.... i used like above coding...but it is not working...Help me pls....