Easy: binding question

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
On this site:
http://www.4guysfromrolla.com/webtech/082901-1.shtml

He binds a dataset to datagrid:
Pubs.DataSource = DS
Pubs.Databind()

But I have a radiobuttonlist.. How can I bind radiobuttonlist to dataGrid? doable??

This is what I have:
Code:
 Dim dg As DataGrid = New DataGrid()


            Dim myDS As DataSet = New DataSet("test")
            Dim myDA As SqlDataAdapter = New SqlDataAdapter()
            myDA.SelectCommand = cmd
            myDA.Fill(myDS, "test")
            Dim RcdCount = myDS.Tables("test").Rows.Count.ToString

            dg.DataSource = myDS
            dg.DataBind()
         [b]rblDisplayIncidents.DataSource = ?????
            rblDisplayIncidents.DataBind()[/b]
            dg.AllowPaging = True
            dg.AllowCustomPaging = False
            dg.PageSize = 3
            dg.PagerStyle.Visible = False
 
Hi...I didn't understand the part where you said "How can I bind radiobuttonlist to dataGrid?"...I take that you want to bind the data from the dataset to a radiobuttonlist. Isnt't it?

If that is the case, I think we cannot give a dataset or a datareader as a DataSource to the radiobuttonlist. You can do it this way:

Querying on the Northwind database:
=======================================================
'1. Create a connection
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

'2. Create the command object, passing in the SQL string
Const strSQL As String = "select top 10 * from orders"
Dim myCommand As New SqlCommand(strSQL, myConnection)

Dim ds As New DataSet
'Set the datagrid's datasource to the datareader and databind
myConnection.Open()
Dim da As New SqlDataAdapter
da.SelectCommand = myCommand
da.Fill(ds)
myConnection.Close()
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim li As New ListItem(dr(0), dr(0))
Me.RadioButtonList1.Items.Add(li)
Next
=======================================================

SJ
 
Last edited:
I want to databind like up but I can not convert my code!
Code:
void ControlBinder3()
		{		
			string strCon = ConfigurationSettings.AppSettings["ConnStr"];
			SqlConnection objConn = new SqlConnection(strCon);      						 

			//Create a command object for the query
			string strSQL ="SELECT RName FROM tblPoll";
			SqlCommand objCmd = new SqlCommand(strSQL, objConn);

			DataSet ds =new DataSet();
			objConn.Open();      

			SqlDataAdapter da1 = new SqlDataAdapter();
			da1.SelectCommand = objCmd;

			da1.Fill(ds);
			DataRow dr ;

			foreach (DataRow dr in ds.)
			{
				ListItem li = new ListItem(dr(0),dr(0));
				RadioButtonList1.Items.Add(li);

			}
Help me
 
Me.RadioButtonList1.DataSource = dataset1.Tables(0)
Me.RadioButtonList1.DataTextField = "mytextfield"
Me.RadioButtonList1.DataValueField = "myValueField"
Me.RadioButtonList1.DataBind()
 
Back
Top