本文介绍了Gridview的RowEditing事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用gridview的RowEditing事件获取datakey值并将其分配给隐藏字段。
但是,我没能得到它。
代码为:
Hi, I want to use RowEditing event of gridview to get datakey value and assign it to hidden field.
But, i failed to get that.
code as :
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvUsers.DataSource = Model.dsAllUsers();
gvUsers.DataBind();
}
}
protected void gvUsers_DataBound(object sender, EventArgs e)
{
gvUsers.HeaderStyle.BackColor = System.Drawing.Color.Gray;
}
protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e)
{
hfVal.Value = gvUsers.DataKeys[e.NewEditIndex].Value.ToString();
//pnlSave.Visible = false;
}
</script>
<body önload="PageLoadEvent();">
<form id="frm" runat="server">
<div>
<asp:GridView ID="gvUsers" runat="server" ondatabound="gvUsers_DataBound"
onrowediting="gvUsers_RowEditing" DataKeyNames="id"
onrowcommand="gvUsers_RowCommand">
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Help me.
推荐答案
protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e)
{
gvUsers.EditIndex = e.NewEditIndex;
getdata(); //got data from table(ie:select * from table)
}
谢谢你。
thank u.
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(); //Initial Binding on load
}
}
protected void gvUsers_DataBound(object sender, EventArgs e)
{
gvUsers.HeaderStyle.BackColor = System.Drawing.Color.Gray;
}
//Get the data and bind it to the GridView
private void BindData()
{
gvUsers.DataSource = Model.dsAllUsers();
gvUsers.DataBind();
}
protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e)
{
gvUsers.EditIndex = e.NewEditIndex;
BindData();
}
</script>
- HTH
谢谢,
Nilesh
- HTH
Thanks,
Nilesh
这篇关于Gridview的RowEditing事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!