473,545 Members | 289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RadioButtonList in a DataGrid

Anyone have any pointers on how to set the Value and Selected attributes in
a ListItem in a RadioButtonList that is in a DataGrid?

Here's what I have
------DataGrid------
-- BoundColumn 0 --
-- BoundColumn 1 --
-- BoundColumn 2 --
-- TemplateColumn 4 --
-- RadioButtonList --
ListItem 0 // need to set the Value and Selected attributes from
DataSet Bound to DataGrid

TIA,
George
Nov 18 '05 #1
5 5500
Oh, and this is the error message I'm getting:

Compiler Error Message: CS0117: 'System.Web.UI. WebControls.Lis tItem' does
not contain a definition for 'DataBinding'

-g

"DotNetGruv en" <ms********@jav agruven.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid?

Here's what I have
------DataGrid------
-- BoundColumn 0 --
-- BoundColumn 1 --
-- BoundColumn 2 --
-- TemplateColumn 4 --
-- RadioButtonList --
ListItem 0 // need to set the Value and Selected attributes from DataSet Bound to DataGrid

TIA,
George

Nov 18 '05 #2
You should be able to DataBind to the List, but not the List Item.

If you want to just set the value on the ListItem, give the
RadioButtonList an id (i.e., rblList) and code the OnDataBindingEv ent
for the DataGrid something like:

//set list item
RadioButtonList myList = (RadioButtonLis t) e.Item.FindCont rol("rblList");
myList.Items[0].Value = <value>;
myList.Items[0].Selected=true/false;

OR
//Bind radiobuttonlist
RadioButtonList myList = (RadioButtonLis t) e.Item.FindCont rol("rblList");
myList.DataSour ce = yourSource;
myList.DataBind ();

Hope this helps
DotNetGruven wrote:
Oh, and this is the error message I'm getting:

Compiler Error Message: CS0117: 'System.Web.UI. WebControls.Lis tItem' does
not contain a definition for 'DataBinding'

-g

"DotNetGruv en" <ms********@jav agruven.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any pointers on how to set the Value and Selected attributes


in
a ListItem in a RadioButtonList that is in a DataGrid?

Here's what I have
------DataGrid------
-- BoundColumn 0 --
-- BoundColumn 1 --
-- BoundColumn 2 --
-- TemplateColumn 4 --
-- RadioButtonList --
ListItem 0 // need to set the Value and Selected attributes


from
DataSet Bound to DataGrid

TIA,
George


Nov 18 '05 #3
Hi George,
Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you has a DataGrid which contains a template column
with a radiobuttonlist in it.
Also you want to set the radionbuttonlis t 's item value and select
attribute at runtime during
the time when DataGrid's column is being bind to the data retrieved from
database, yes?
If there is anything I misunderstood, please feel free to let me know.
As for this problem, I think we can use the DataGrid's DataItemBound event
to implement our requirement. In the DataItemBound event, we can retrieve
the certain row which is currently being bund with datas from the
DataSource. Also, we can retrieve the certain row of DataSource. For our
siutation, we want to do some modification on the radiobuttonlist in the
template collumn, we can first retrieve the RadioButtonList control from
the column using "FindContro l" and then do operations on it. For example:

private void dgMain_ItemData Bound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
DataRowView drv = (DataRowView)e. Item.DataItem;
System.Web.UI.W ebControls.Radi oButtonList lst =
(System.Web.UI. WebControls.Rad ioButtonList)e. Item.Cells[2].FindControl("r blB
ind");
lst.Items[0].Text = drv["grade"].ToString();
lst.Items[0].Value = drv["grade"].ToString();
lst.SelectedInd ex = 0;
}
}

#dgMain is the DataGrid in a page

To make such approach clearly, here is a sample page I've made, you can
refer to it if you have anything unclear in my above description:
---------------------------------aspx page----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>RadioBut tonList</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:DataGrid id="dgMain" runat="server" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n DataField="inde x"
HeaderText="ID" ></asp:BoundColumn >
<asp:BoundColum n DataField="name "
HeaderText="Nam e"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Bou ndList">
<ItemTemplate >
<asp:RadioButto nList id="rblBind" runat="server">
<asp:ListItem Value="BindItem ">BindItem</asp:ListItem>
<asp:ListItem Value="ItemA">I temA</asp:ListItem>
<asp:ListItem Value="ItemB">I temB</asp:ListItem>
<asp:ListItem Value="ItemC">I temC</asp:ListItem>
</asp:RadioButton List>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</HTML>

-----------------------------code behind page class------------------
public class RadioButtonList : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid dgMain;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
BindGrid();
}
}

protected void BindGrid()
{
DataTable tb = new DataTable();
tb.Columns.Add( "index");
tb.Columns.Add( "name");
tb.Columns.Add( "grade");

for(int i=0;i<15;i++)
{
int index = i+1;
DataRow newrow = tb.NewRow();
newrow["index"] = index.ToString( );
newrow["name"] = "name" + index.ToString( );
switch(index%3)
{
case 0:
newrow["grade"] = "low";
break;
case 1:
newrow["grade"] = "normal";
break;
case 2:
newrow["grade"] = "high";
break;
}

tb.Rows.Add(new row);
}

dgMain.DataSour ce = tb;
dgMain.DataBind ();

}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.dgMain.Ite mDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.dgMa in_ItemDataBoun d
);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void dgMain_ItemData Bound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
DataRowView drv = (DataRowView)e. Item.DataItem;
System.Web.UI.W ebControls.Radi oButtonList lst =
(System.Web.UI. WebControls.Rad ioButtonList)e. Item.Cells[2].FindControl("r blB
ind");
lst.Items[0].Text = drv["grade"].ToString();
lst.Items[0].Value = drv["grade"].ToString();
lst.SelectedInd ex = 0;

}
}
}
----------------------------------------------------------------------------
-------------------------

If you have any further questions, please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #4
Thanks Ruprict, your help below set me down the right path to the answer. Here is what worked:

public void OnItemDataBound (object sender, System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
ListItemType listItemType = e.Item.ItemType ;
if ( listItemType == ListItemType.Al ternatingItem || listItemType == ListItemType.It em )
{
TableCell cell;
cell = (TableCell) e.Item.Cells[5];
if ( cell.Controls[1]is RadioButtonList && e.Item.DataItem is DataRowView )
{
RadioButtonList rbl = (RadioButtonLis t)cell.Controls[1];
DataRowView dr = (DataRowView)e. Item.DataItem;
rbl.Items[0].Selected = Convert.ToBoole an(dr.Row.ItemA rray[5]);
rbl.Items[1].Selected = !rbl.Items[0].Selected;
rbl.Items[0].Value = rbl.Items[1].Value = dr.Row.ItemArra y[0].ToString();
}
}
}

"Ruprict" <ru*****@bellso uth.net> wrote in message news:cT******** *********@bigne ws6.bellsouth.n et...
You should be able to DataBind to the List, but not the List Item.

If you want to just set the value on the ListItem, give the
RadioButtonList an id (i.e., rblList) and code the OnDataBindingEv ent
for the DataGrid something like:

//set list item
RadioButtonList myList = (RadioButtonLis t) e.Item.FindCont rol("rblList");
myList.Items[0].Value = <value>;
myList.Items[0].Selected=true/false;

OR
//Bind radiobuttonlist
RadioButtonList myList = (RadioButtonLis t) e.Item.FindCont rol("rblList");
myList.DataSour ce = yourSource;
myList.DataBind ();

Hope this helps


DotNetGruven wrote:
Oh, and this is the error message I'm getting:

Compiler Error Message: CS0117: 'System.Web.UI. WebControls.Lis tItem' does
not contain a definition for 'DataBinding'

-g

"DotNetGruv en" <ms********@jav agruven.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any pointers on how to set the Value and Selected attributes


in
a ListItem in a RadioButtonList that is in a DataGrid?

Here's what I have
------DataGrid------
-- BoundColumn 0 --
-- BoundColumn 1 --
-- BoundColumn 2 --
-- TemplateColumn 4 --
-- RadioButtonList --
ListItem 0 // need to set the Value and Selected attributes


from
DataSet Bound to DataGrid

TIA,
George



Nov 18 '05 #5
Hi George,
Thanks for your followup. I'm glad that the problem has been resolved. In
the meantime, if you have any further questions or need any further help,
please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4305
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load i create dynamically a table which contains a checkbox and a radiobuttonlist in each tablerow . The radiobuttonlist contains two items (yes,no). Both the checkboxes and the radiobuttonlist are NOT autopostbacked ( .autopostback = false). When i press the submit button a...
0
1817
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I then check some boxes and hit the submit button. I can't seem to get the value that is selected on the RadioButton List. I don't want to use the...
0
1792
by: Bob Hoke | last post by:
I am trying to do some of the things we used to do in classic ASP that required some pretty ugly loops in the .ASP page. I have two different DataSets that each have a DataView that I can change based on parameters passed in. In my .ASPX page I have created a loop (using <% ..%> blocks) that contains two different DataGrids. The loop...
1
2830
by: Tim | last post by:
I have a RadioButtonList inside the EditItemTemplate of a Datagrid. On the Edit command of the datagrid I am calling the following command: public void dgNodeBranches_Edit(object sender, DataGridCommandEventArgs e) { RadioButtonList rblNodeOptions = (RadioButtonList)e.Item.FindControl("rblNodeOptions");
6
7714
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and update the database. Here is the control containment hierarchy: ASP Page Static User Control // just provides a pretty border around
0
1951
by: Luis Esteban Valencia | last post by:
http://www.codeproject.com/aspnet/DataGridCCEvents.asp#xx1009236xx Read this first and see if you can help me have tried but the Intelisense of the radiobuttonlist doestn have the event selectedindexchanged? I have a datagrrid with an itemtemplate, inside this itemtemplate thre is a radiobuttonlist with 3 options. There is also a label to...
2
2093
by: Brian | last post by:
I have a datagrid that is listing a bunch of questions from my DB.. I am creating a radiobuttonlist for each question to give me a yes or no answer. I would like to use the "QuestionCode" column from that database to assign the radiobuttonlist ID. Is this possible??????
0
1168
by: ad | last post by:
I have a tabe with a filed SexID, it use 1 for Male and 2 for Female. I want to let user can edit this in a DataGrid with a RadioButtonList. I add a RadioButtonList in the EditItemTemplate: ---------------------------------------------------------------------------- ---------------- <EditItemTemplate> <asp:RadioButtonList...
0
1379
by: rcoco | last post by:
Hi, Ihave a datagrid that Insert data in some rows. One column has RadioButtonList that contains three Items. But When I select one radiobuton, insert data in other columns and select insert data The radio button unselects itself. Why would this be happening? here is my code. DataTable table = new DataTable(); private DataTable Fill() {
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.