0

I have two GridViews. GridView1 contains 2 link buttons in a column. When I select a link button in GridView1, the details of the link button should be displayed in GridView2.

GridView2 contains a column with radio buttons. I need to fill the radio buttons dynamically from the database.

How can I fill the Radio button list of GridView2 by using GridView1_RowCommand? Or Can I get it from the RowDataBound event of GridView2?

code behind:

protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{            
    if (e.CommandName == "Yes")
    {           
        GridViewRow gvRow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        int RowIndex = gvRow.RowIndex;            
        Int32 iAppID = Convert.ToInt32(GridView1.DataKeys[gvRow.RowIndex].Value.ToString());               

        dset = userApps.UserSelectedApp(iUserID, iAppID);
        if (dset.Tables[0].Rows.Count > 0)
        {
            GridViewRow gRow = GridView2.Rows[RowIndex];//I need to create object to this Gridview2, and fill the radiobutton list with some values
            RadioButtonList rdbtnSubPlans = (RadioButtonList)e.gRow.Cells[2].FindControl("rdbSubPlans");

            ds = userApps.UpgradePlans(iUserID, iAppID);
            if (ds != null)
            {
                rdbtnSubPlans.DataSource = ds;
                rdbtnSubPlans.DataValueField = "PlanID";
                rdbtnSubPlans.DataTextField = "Plans";
                rdbtnSubPlans.DataBind();
            }
        }
    }
    if (e.CommandName == "No")
    {}
     dtset = user.UserSelectedAppication(iUserID, iAppID);    
     GridView2.DataSource = dtset;
     GridView2.DataBind();
     MultiView1.SetActiveView(viewRenewOrUpdate);                
    }
}  

ASPX code for the GridViews

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ApplicationID" 
    OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" 
    OnSorting="GridView1_Sorting" OnDataBound="GridView1_DataBound"
    OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField HeaderText="S.No" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center">
            <ItemTemplate>
                <asp:Label ID="l1" runat="server" Text="1"></asp:Label>
            </ItemTemplate>
            <HeaderStyle Width="10%" />
        </asp:TemplateField>
        < Some Bound Fields>                                                   
        <asp:TemplateField HeaderText="Action">
            <ItemTemplate>
                <asp:LinkButton ID="lnkYes" runat="server" Text="Yes" 
                    CssClass="lnkbtn" Visible="false" commandname="Yes" Width="100px" >
                </asp:LinkButton>
                &nbsp;
                <asp:LinkButton ID="lnkNo" runat="server" CssClass="lnkbtn" Text="No" 
                    Visible="false" commandname="No" ToolTip="No and Yes current plan" Width="100px" >
                </asp:LinkButton>
            </ItemTemplate>                                                        
        </asp:TemplateField>
    </Columns>                                               
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" DataKeyNames="ApplicationID"
    OnRowDataBound="GridView2_RowDataBound">
    <Columns>
        <asp:BoundField DataField="ApplicationName" HeaderText="Application name">
            <HeaderStyle Width="30%" />
            <ItemStyle CssClass="col" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Plans">
            <ItemTemplate>
                <asp:RadioButtonList ID="rdbSubPlans" runat="server" AutoPostBack="true" 
                    OnSelectedIndexChanged="rdbSubPlan_OnSelectedIndexChanged" Enabled="false">
                </asp:RadioButtonList>
            </ItemTemplate>
        <ItemStyle CssClass="col" />
    </Columns>
</asp:GridView>
9
  • 2
    so what is the problem? Commented Dec 16, 2013 at 13:30
  • I need to get the radio button list in the GridView2. I am getting an error like System.Web.UI.WebControls.GridViewCommandEventArgs' does not contain a definition for 'gRow' and no extension method 'gRow' accepting a first argument of type 'System.Web.UI.WebControls.GridViewCommandEventArgs' could be found (are you missing a using directive or an assembly reference? Commented Dec 16, 2013 at 13:34
  • The RowCommand event is of GridView1, Based on the selected link button of GridView1 I need to fill a column of GridView2 with radio button list. Commented Dec 16, 2013 at 13:38
  • can you show your aspx page Gridviews html Commented Dec 16, 2013 at 13:41
  • why is your if (e.CommandName == "No") inside if (e.CommandName == "Yes") body? Commented Dec 16, 2013 at 13:45

1 Answer 1

1

Fill Gridview2 first, and then do the following corrections:

GridViewRow gRow = GridView2.Rows[0]
RadioButtonList rdbtnPlans = (RadioButtonList)gRow.FindControl("rdbPlans");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.