Data Binding works but why no value?
hi guys,
I try to write a simple data binding function.
I create a RadioButtonList and i connect to the database and bind the Radio with the DataTable that I got from DataSet.
and I create a print button and i want to fill the lblDisplay with the selected value from the radio. somehow, the selectedIndex from the radio is -1.
Can somebody help me plz...here is the code.
private void Page_Load(object sender, System.EventArgs e){
// Put user code to initialize the page here
string conn = "Persist Security Info=false;database=my_data;uid=my_user;pwd=my_pas s;host=localhost";
string cmd = "Select * From Visitors";
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd,conn);
DataSet data = new DataSet();
adapter.Fill(data,"Visitors");
DataTable Visitors = data.Tables["Visitors"];
rbVisitor.DataSource = Visitors; //i called my radiolist with rbVisitor
rbVisitor.DataValueField = "vistID";
rbVisitor.DataTextField = "vistName";
rbVisitor.DataBind();
if (!IsPostBack){
rbVisitor.SelectedIndex = 0;
}
}
private void btnPrint_Click(object sender, System.EventArgs e)
{
lblDisplay.Text = rbVisitor.SelectedItem.Text.ToString(); //this part give no value, It print out OK though on the screen
}
thanks
|