Need help with radiobuttons in datagrid bind to data table

Discussion in '.NET' started by rwornor, Mar 1, 2008.

  1. rwornor

    rwornor

    Joined:
    Mar 1, 2008
    Messages:
    1
    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);
    }
    }
    }
     
    rwornor, Mar 1, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RB

    RadioButtons & DataGrid

    RB, Aug 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    406
  2. mr2_93
    Replies:
    1
    Views:
    3,602
    mr2_93
    Oct 2, 2005
  3. daokfella
    Replies:
    1
    Views:
    382
    daokfella
    Nov 20, 2007
  4. Sheikh Nabeel Moeen

    Grouping RadioButtons in a DataGrid

    Sheikh Nabeel Moeen, Sep 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    124
    Sriram Mallajyosula
    Sep 22, 2004
  5. Net Developer

    Need a list of radiobuttons with a specfic format

    Net Developer, Jun 7, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    143
    Visar Gashi, MCP
    Jun 8, 2005
Loading...

Share This Page