【发布时间】:2013-12-16 13:26:39
【问题描述】:
我有两个 GridView。 GridView1 在一列中包含 2 个链接按钮。当我在 GridView1 中选择链接按钮时,链接按钮的详细信息应显示在 GridView2 中。
GridView2 包含一个带有单选按钮的列。我需要从数据库中动态填充单选按钮。
如何使用 GridView1_RowCommand 填充 GridView2 的单选按钮列表?或者我可以从 GridView2 的 RowDataBound 事件中获取它吗?
后面的代码:
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);
}
}
GridViews 的 ASPX 代码
<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>
<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>
【问题讨论】:
-
那么问题出在哪里?
-
我需要获取GridView2中的单选按钮列表。我收到类似 System.Web.UI.WebControls.GridViewCommandEventArgs 的错误,它不包含“gRow”的定义,并且没有扩展方法“gRow”接受“System.Web.UI.WebControls”类型的第一个参数。可以找到 GridViewCommandEventArgs'(您是否缺少 using 指令或程序集引用?
-
RowCommand 事件属于 GridView1,基于 GridView1 的选定链接按钮,我需要用单选按钮列表填充 GridView2 的一列。
-
你能显示你的aspx页面Gridviews html
-
为什么你的 if (e.CommandName == "No") 在 if (e.CommandName == "Yes") body 里面?