62,243
社区成员




在 父Gridview 那个事件下 获取主键值 给 Index;
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Index = Convert.ToInt16(e.CommandArgument.ToString());//我这样写不行我在 前台怎么给 CommandArgument赋值?
Response.Write(e.CommandArgument.ToString().Length);//结果是 :0
}
protected void ClassChild_RowEditing(object sender, GridViewEditEventArgs e)
{ GridView ClassChild = (GridView)sender;
ClassChild.EditIndex = e.NewEditIndex;
BindChild(ClassChild); }
protected void BindChild(GridView gv)
{
gv.DataSource = Bll.GetList("SD_class.SD_ParentId =" + Convert.ToInt16(GridView1.DataKeys[Index].Values[0]) + "and SD_class.SD_Level=2"); //现在报错的地方就是 这个 "Index";
gv.DataBind();
}
private int Index
{
get
{
if (ViewState["Index"] != null && ViewState["Index"].ToString() != "")
{
return Convert.ToInt32(ViewState["Index"]);
}
else
{
return -1;
}
}
set
{
ViewState["Index"] = value;
}
}
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("SD_ClassId") %>' CommandName="Delete"
Text="删除"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="AddClass" runat="server" CausesValidation="False" CommandName="AddClass"
Text="添加栏目"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
CommandArgument=' <%# DataBinder.Eval(Container,"RowIndex") %>'
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "Delete")
{ Index = Convert.ToInt16(e.CommandArgument.ToString());//我这样写不行我在 前台怎么给 CommandArgument赋值?
Response.Write(e.CommandArgument.ToString().Length);//结果是 :0
}
}