473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Workaround for Bug: Q316495

I have a datagrid where I need to display a list of radiobuttons for each
row. Unfortunatly, RadioButtonList does not meet my requirements because I
need some flexibilty for formatting. So, I added a Repeater control (I tried
Repeater and DataList) to a TemplateColumn to display the list of radio
buttons. Here is an example:
<asp:TemplateColumn>
<ItemTemplate>
<asp:DataList id="dlPrintFormat" runat="server">
<ItemTemplate>
<table>
<tr>
<td><input type="radio" name="radFormat"
runat="server" value="somevalue"><asp:Label runat="server"
id="lblFormatDescription" text='databoundtext'/></td>
<td><asp:Label runat="server" id="lblPrice"
text='databoundtext'/></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:TemplateColumn>

Unfortuanetly the aforementioned bug does not allow a mutually exclusive set
of radio buttons inside of a repeater, datalist or datagrid (for more
details see Q316495). The third thing I tried (and I am really struggling
with this one) is to dynamically create the above layout at runtime in the
ItemDataBound event for the parent DataGrid. I am trying to do this with a
PlaceHolder control. At runtime I create the table, rows, cells,
radiobuttons and labels like this:

public void LoadChildRecords(object Sender, DataGridItemEventArgs e){
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item){
DataView dvOptions =
((DataRowView)e.Item.DataItem).CreateChildView("Pr oductOptions");
//the datasource for the datagrid is a dataset w/ 2 tables and one relation
named "ProductOptions"

System.Web.UI.HtmlControls.HtmlTable tbl = new HtmlTable();
tbl.Border = 0;
tbl.CellPadding = 0;
tbl.CellSpacing = 0;
tbl.Width = "100%";
for(int i=0; i<dvOptions.Count; i++){
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell();
HtmlInputRadioButton rad = new HtmlInputRadioButton();
rad.ID = "radFinish";
rad.Name = "radFinish";
rad.Value = dvOptions[i]["ProductSKU"].ToString();
rad.EnableViewState = true;
Label lblFinish = new Label();
lblFinish.Text = dvOptions[i]["FinishDescription"].ToString();
if(i==0){
rad.Checked = true;
}
td.Controls.Add(rad);
td.Controls.Add(lblFinish);
tr.Cells.Add(td);
HtmlTableCell td2 = new HtmlTableCell();
Label lbl = new Label();
lbl.Text =
Double.Parse(dvOptions[i]["MSRP"].ToString()).ToString("C");
td2.Controls.Add(lbl);
tr.Cells.Add(td2);
tbl.Rows.Add(tr);
}
phdPrintFinish = (PlaceHolder)e.Item.FindControl("phdPrintFinish");
phdPrintFinish.Controls.Add(tbl);

}
}

However, those controls are not there at postback. I have read that I must
create them during the Page_OnInit event, but what I don't get is how I
could do that when I don't know how many controls need to be created until I
have the data. Can I create and bind the Datagrid and create the controls
all during the Page_OnInit event? I have considered creating a Server
Control which inherits from RadioButton list and overriding the render
method, but I'm still a bit green in a lot of areas and I don't quite know
where to start if I were to do that.

So is there a more efficient (or simple) way to accomplish this?

Thanks,
Mark
Nov 17 '05 #1
0 1595

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

Similar topics

3
by: Russell E. Owen | last post by:
I stumbled across a really strange bug involving directories on linux. os.path.exists(path) can return 0 even after os.path.mkdir(path) succeeds (well after; this isn't a timing issue). For...
0
by: Jonas Smithson | last post by:
<div style="position: relative;> <!-- I'm the parent --> blah blah blah <div style="position: absolute; bottom: 0;> <!-- I'm the child --> blah blah blah </div> </div> The bottom of the...
3
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing...
7
by: Justin Shen | last post by:
the output of the following codes is "greater than zero", which is rather strange! the correct one should be "not greater than zero" int a = 0x79de61c0; //2044617152; a += 0x12345678; //a is...
1
by: Bart Jacobs | last post by:
Dear VC++ team, I am fairly certain I found a bug in VC++ 7.1. I get the following error ======================================================================== Microsoft (R) C/C++...
16
by: PyDenis | last post by:
Today, I found strange error while using py2exe: 1. I wrote simple program and save as 1.py: import win32ui import win32con win32ui.MessageBox('Test messageBox.' , 'Test', win32con.MB_OK |...
0
by: Sven Rudolph | last post by:
Hi, I just made a web site and stumbeled upon something, that seems to be a stylesheets bug in Konqueror. When Iuse :first-letter on the a-tag, Konqueror doubles the first letter when I click...
0
by: Gustaf | last post by:
Using VS 2005. I'm hardly the first to discover this, but here's a description of the bug as I found it: 1. Make a new form. 2. Add a SplitContainer and make it horizontal. 3. Add a TabControl...
1
by: basm101 | last post by:
Hello, I am using javascript to dynamically add some rows to a form. I know that IE has a problem with certain DOM stuff. (e.g. needs className instead of class) I am trying to set the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.