我用GridView绑定数据
public void BindToDept()
{
department dept = new department();
this.Gdept.DataSource = dept.GetAlldepartment();
this.Gdept.DataKeyNames = new string[]{ "DepartmentId" };
this.Gdept.DataBind();
}然后我想获取所选定行内容的ID主键或是内容的相关信息,我的代码是
string id = Gdept.DataKeys[Gdept.SelectedIndex].Value.ToString();
为什么提示我出错误:索引超出范围。有知道的朋友吗,指点一二,哪错了?还是有更好的方法来实现,请详细说明,谢谢。
public void BindToDept()
{
department dept = new department();
this.Gdept.DataSource = dept.GetAlldepartment();
this.Gdept.DataKeyNames = new string[]{ "DepartmentId" };
this.Gdept.DataBind();
}然后我想获取所选定行内容的ID主键或是内容的相关信息,我的代码是
string id = Gdept.DataKeys[Gdept.SelectedIndex].Value.ToString();
为什么提示我出错误:索引超出范围。有知道的朋友吗,指点一二,哪错了?还是有更好的方法来实现,请详细说明,谢谢。
<font style="FONT-SIZE: 12px" color="Black">
<%# DataBinder.Eval(Container.DataItem, "DepartmentName")%>
</font></asp:LinkButton>
这个代码的事件写错了呢?
我写的是 protected void Gdept_RowCommand(object sender, GridViewCommandEventArgs e)
急,请指教
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="select">
<%# DataBinder.Eval(Container.DataItem, "DepartmentName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DepartmentId" />
<asp:ButtonField Text="选择" CommandName="select" />
</Columns>
</asp:GridView>
cs.
protected void Gdept_SelectedIndexChanged(object sender, EventArgs e)
{
string id = Gdept.DataKeys[Gdept.SelectedIndex].Value.ToString(); Response.Redirect("testaddpersons.aspx?id=" + id);
}
可是代码跟本不走Gdept_SelectedIndexChanged这个事件啊运行提示:未找到有效资源
到处都见的到cpp2017(慕白兄)
GridView1_SelectedIndexChanged中
--------------------------------------------------------------------------------无法找到资源。
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
写在GridView1_SelectedIndexChanged中 出现上面的错误