Need help with radiobuttons in datagrid bind to data table

Joined
Mar 1, 2008
Messages
1
Reaction score
0
Guys/Gals could I please get some help with this issue. I've successfully created radio button selection options in a data grid. But when I select a radio button (example "RButton1") and hit the submit button, "RButton1" return False for the checked option. checked is never toggled to true. Here is my code. Bottom line is I expect "RButton1" to return "True" in the "PlaceHolder1" area for its Checked option when selected. The value returned is always "False". Is this because I haven't built the toggle option. If not how do I do that without setting autopostback to true and without using client-side javascript?

ASPX:

<div style="width:388px; height:250px; margin-left:138px; overflow-y:auto; scrollbar-face-color: #FFE3BF;scrollbar-shadow-color: #FFE3BF;scrollbar-highlight-color: #FFE3BF;scrollbar-3dlight-color:#543C1C;scrollbar-darkshadow-color: #543C1C;scrollbar-track-color: #FFE3BF;scrollbar-arrow-color: #543C1C;" id="rowdiv">
<asp:DataGrid id=Grid1 runat=server Font-Size="7pt" Font-Names="Verdana" ForeColor="#543C1C" HeaderStyle-Font-Bold="true" BorderStyle="None" BorderWidth="0px" ShowHeader="false" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn HeaderText="LBL0" DataField="LBL0" ItemStyle-Width="127px"></asp:BoundColumn>
<asp:TemplateColumn ItemStyle-Width="60px">
<ItemTemplate>
<center>
<asp:RadioButton ID="RButton1" runat=server Text='<%# (string)(((DataRowView)Container.DataItem)["RButton1"]) %>' GroupName="ChkdButton"></asp:RadioButton>
</center>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-Width="60px">
<ItemTemplate>
<center>
<asp:RadioButton ID="RButton2" runat=server Text='<%# (string)(((DataRowView)Container.DataItem)["RButton2"]) %>' GroupName="ChkdButton"></asp:RadioButton>
</center>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-Width="60px">
<ItemTemplate>
<center>
<asp:RadioButton ID="RButton3" runat=server Text='<%# (string)(((DataRowView)Container.DataItem)["RButton3"]) %>' GroupName="ChkdButton"></asp:RadioButton>
</center>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-Width="60px">
<ItemTemplate>
<asp:RadioButton ID="RButton4" runat=server Text='<%# (string)(((DataRowView)Container.DataItem)["RButton4"]) %>' GroupName="ChkdButton"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</div>
<table border="0" cellpadding="1" cellspacing="0" style="width:100px; height:10px; margin-left:427px; margin-top:5px;">
<tr valign=top align=left>
<td>
<asp:ImageButton ID="SubmitButton" style="margin-left:5px;" ImageUrl="~/images/ImageButton1.gif" runat="server" OnClick="processSubmit"/>
</td>
</tr>
</table>
<table border="0" cellpadding="1" cellspacing="0" style="width:400px; height:80px; margin-left:115px;">
<tr valign=top align=left>
<td>
<asp:placeHolder ID="PlaceHolder1" runat="server"></asp:placeHolder>
</td>
</tr>
</table>

CS:
static DataTable dt = new DataTable();
static DataView dv = new DataView();
protected void Page_Load(object sender, EventArgs e)
{
LoadMenu(CustomerKey, UserKey);
}
public void LoadMenu(String selectionKey, String loggedInKey)
{
if (dt.Columns.Count == 0)
{
Grid1.DataSource = FetchGridList();
Grid1.DataBind();
AddRadioButtonsToGrid1();
}
else
{
dv = new DataView(dt);
Grid1.DataSource = dv;
Grid1.DataBind();
}
}
ICollection FetchGridList()
{
int i = 0;
DataRow dr;
dt.Columns.Add(new DataColumn("LBL0", typeof(string)));
dt.Columns.Add(new DataColumn("RButton1"));
dt.Columns.Add(new DataColumn("RButton2"));
dt.Columns.Add(new DataColumn("RButton3"));
dt.Columns.Add(new DataColumn("RButton4"));

for (i=0; i<15; i++)
{
dr = dt.NewRow();
dr[0] = "Row" " " i + "<br>";
dr[1] = false;
dr[2] = false;
dr[3] = false;
dr[4] = false;
dt.Rows.Add(dr);
i++;
}
dv = new DataView(dt);
return dv;
}
public void AddRadioButtonsToGrid1()
{
if (!IsPostBack)
{
int i = 0;
for (i=0; i<15; i++)
{
DataGridItem nItem = Grid1.Items;
RadioButton nRButton1 = (RadioButton)nItem.FindControl("RButton1");
nRButton1.Text = "Row" + i + "Button" + i + "<br>";
RadioButton nRButton2 = (RadioButton)nItem.FindControl("RButton2");
nRButton2.Text = "Row" + i + "Button" + i + "<br>";
RadioButton nRButton3 = (RadioButton)nItem.FindControl("RButton3");
rnRButton3.Text = "Row" + i + "Button" + i + "<br>";
RadioButton nRButton4 = (RadioButton)nItem.FindControl("RButton4");
nRButton4.Text = "Row" + i + "Button" + i + "<br>";
DataRow newDr = dt.Rows;
newDr[1] = nRButton1.Text;
newDr[2] = nRButton2.Text;
newDr[3] = nRButton3.Text;
newDr[4] = nRButton4.Text;
i++;
}
Grid1.DataSource = dv;
Grid1.DataBind();
}
}
public void processSubmit(object sender, EventArgs e)
{
for (int i=0; i<15; i++)
{
DataGridItem chkdItem = Grid1.Items;
RadioButton RCButton1 = ((RadioButton)chkdItem.FindControl("RButton1"));
RadioButton RCButton2 = ((RadioButton)chkdItem.FindControl("RButton2"));
RadioButton RCButton3= ((RadioButton)chkdItem.FindControl("RButton3"));
RadioButton RCButton4 = ((RadioButton)chkdItem.FindControl("RButton4"));
Label Label1 = new Label();
Label1.Text = RCButton1.Checked.ToString() + "<br>";
Label1.Style.Add(HtmlTextWriterStyle.MarginLeft, "24px");
Label1.Style.Add(HtmlTextWriterStyle.Color, "#543C1C");
Label1.Style.Add(HtmlTextWriterStyle.FontFamily, "Verdana");
Label1.Style.Add(HtmlTextWriterStyle.FontSize, "8pt");
Label1.Style.Add(HtmlTextWriterStyle.Width, "75px");
Label1.Style.Add(HtmlTextWriterStyle.Height, "10px");
PlaceHolder1.Add(Label1);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top