Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:


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

Posted (edited)

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

Edited by sj1187534
  • 1 month later...
Posted

I want to databind like up but I can not convert my 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...