Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to retrieve value of chkbox from radio button selected index ??

CODE IS :

<asp:DropDownList ID="ddSr" runat="server" AutoPostBack="true"
          EnableTheming="True" Height="16px"
          onselectedindexchanged="ddSr_SelectedIndexChanged" Width="190px">
      </asp:DropDownList>

<asp:RadioButtonList ID="rdoSr" runat="server" AutoPostBack="True"
                          onselectedindexchanged="rdoSr_SelectedIndexChanged">
          </asp:RadioButtonList>


C#
protected void rdoSr_SelectedIndexChanged(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand("Customer_FullJoin_State_Retrieve", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@SNo", rdoSr.SelectedItem.Value);


        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        reader.Read();
        {
//Error Showing Here
            chkSr.SelectedItem.Value = reader["State"].ToString();  


            reader.Close();
        }
        conn.Close();
    }


SQL
ALTER procedure [dbo].[Customer_FullJoin_State_Retrieve]
@SNo int
as
select Customer.City AS City1,State.City AS City2,Customer.Sr_No as Sr_No1, * from Customer full Join State on Customer.City = State.City
where Customer.Sr_No=@SNo
RETURN


Thanks.
Posted
Updated 10-May-11 3:41am
v2
Comments
Ankur\m/ 10-May-11 9:50am    
chkSr.SelectedItem.Value = reader["State"].ToString();

I am considering chkSr is the id of your checkbox. Do you want to check the corresponding checkboxes or assign a text against them?
In both case, the code above is not correct.
sat_100m 11-May-11 0:58am    
No, I want chkSr value(selected one) from database and table name "State"...

rdoSr contains same values of state column and I want after select on rdoSr, the value of chksr comes up automatically.

Both rdoSr and chksr contains same values dat's retrieve from column Sate of table State

1 solution

If you just want the control, do this:

RadioButtonList rbl = sender as RadioButtonList;
RadioButtonIterm item = rbl.SelectedItem;


If you want the text of the item., add the Value propetrty:

string text = rbl.SelectedItem.Value;


If you want the index of the item, do this:

int index = rbl.SelectedIndex;
 
Share this answer
 
Comments
sat_100m 11-May-11 0:58am    
No, I want chkSr value(selected one) from database and table name "State"...

rdoSr contains same values of state column and I want after select on rdoSr, the value of chksr comes up automatically.

Both rdoSr and chksr contains same values dat's retrieve from column Sate of table State

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900