关于GridView取模板列的索引相关问题

2024-12-21 21:51:23
推荐回答(1个)
回答1:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//获取编辑行索引
GridView1.EditIndex = e.NewEditIndex;
Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新内容
int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
FriendlyLink flink = FriendlyLinkManager.GetFriendlyLink(id);
flink.Title = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTitle")).Text;
flink.Url = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtUrl")).Text;
FriendlyLinkManager.SaveFriendlyLink(flink);
string url = Request.Url.ToString();
Response.Redirect(url);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消编辑行的索引
GridView1.EditIndex = -1;
Bind();
}