eramgarden Posted April 15, 2004 Posted April 15, 2004 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 Quote
sj1187534 Posted April 16, 2004 Posted April 16, 2004 (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 April 16, 2004 by sj1187534 Quote
shahab Posted May 20, 2004 Posted May 20, 2004 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 Quote
wessamzeidan Posted May 20, 2004 Posted May 20, 2004 Me.RadioButtonList1.DataSource = dataset1.Tables(0) Me.RadioButtonList1.DataTextField = "mytextfield" Me.RadioButtonList1.DataValueField = "myValueField" Me.RadioButtonList1.DataBind() Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
shahab Posted May 20, 2004 Posted May 20, 2004 1-What Me is? 2-what about this part: foreach (DataRow dr in ds.) { Thaks to kindly Palestinian Quote
wessamzeidan Posted May 20, 2004 Posted May 20, 2004 sorry, Me is used in VB.NET, its 'this' in C# Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.