D
dev648237923
I have a simple GridView. I need to do the Select and Edit in the code
behind because I have to change schema prefix in the sql statement depending
on the current user.
I have the data grid and I have event handlers for edit and cancel but an
odd thing happes: I have to click the Edit link twice for it to work and I
need to click the Cancel link twice for it to work (the first postback does
call my funcs but does not have any effect on how the grid looks -- I have
to click the second time to get Update, Cancel to showup on the grid?). Is
the below the correct way to do this? Thank you!
<asp:gridview id="gv1" runat="server"
AutoGenerateColumns="False"
OnRowEditing="gv1_RowEditing"
OnRowCancelingEdit="gv1_RowCancelingEdit">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" ReadOnly="True" />
...more bound fields go here
</Columns>
</asp:gridview>
protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
{
gv1.EditIndex = e.NewEditIndex;
//then call my sql to do the edit
}
protected void gv1_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
gv1.EditIndex = -1;
}
p.s. I know it would be easier/better to design the db around this (have a
usp and pass what schema to use, etc. but I am stuck with it this way so
must do this on the asp.net side
behind because I have to change schema prefix in the sql statement depending
on the current user.
I have the data grid and I have event handlers for edit and cancel but an
odd thing happes: I have to click the Edit link twice for it to work and I
need to click the Cancel link twice for it to work (the first postback does
call my funcs but does not have any effect on how the grid looks -- I have
to click the second time to get Update, Cancel to showup on the grid?). Is
the below the correct way to do this? Thank you!
<asp:gridview id="gv1" runat="server"
AutoGenerateColumns="False"
OnRowEditing="gv1_RowEditing"
OnRowCancelingEdit="gv1_RowCancelingEdit">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" ReadOnly="True" />
...more bound fields go here
</Columns>
</asp:gridview>
protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
{
gv1.EditIndex = e.NewEditIndex;
//then call my sql to do the edit
}
protected void gv1_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
gv1.EditIndex = -1;
}
p.s. I know it would be easier/better to design the db around this (have a
usp and pass what schema to use, etc. but I am stuck with it this way so
must do this on the asp.net side