ОК. Итак, у меня есть веб-приложение с выпадающим полем, кнопкой показа и сеткой, которые я могу редактировать. Страница загружается, я выбираю значение раскрывающегося списка, страница загружается нормально. Однако, когда я нажимаю кнопку редактирования, мне нужно дважды щелкнуть ее, чтобы иметь возможность редактировать или отменить (с этим тоже возникают проблемы, но это уже другая проблема)
В любом случае, я хочу иметь возможность одним нажатием изменить, чтобы вызвать режим редактирования обновления / отмены. Я новичок в веб-приложениях на C #, поэтому было бы полезно кое-что понять.
Спасибо
Мой ASP
<asp:GridView ID="GridView1" runat="server" CssClass="styled"
OnRowEditing="TaskGridView_RowEditing"
OnRowCancelingEdit="TaskGridView_RowCancelingEdit"
OnRowUpdating="TaskGridView_RowUpdating" >
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
My C #
protected void TaskGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
GridView1.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
// BindData();
}
protected void TaskGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//Reset the edit index.
GridView1.EditIndex = -1;
//Bind data to the GridView control.
BindData();
Image1.Visible = true;
Image2.Visible = false;
}
protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
System.Data.DataTable dt = (System.Data.DataTable)Session["EditDataPage"];
//Update the values.
GridViewRow row = GridView1.Rows[e.RowIndex];
// dt.Rows[row.DataItemIndex]["QuoteNumber"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["ItemNumber"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
//dt.Rows[row.DataItemIndex]["IsComplete"] = ((CheckBox)(row.Cells[3].Controls[0])).Checked;
// dt.Rows[row.DataItemIndex]["Item"] = ((TextBox)(row.Cells[3].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["Descp"] = ((TextBox)(row.Cells[4].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["Route"] = ((TextBox)(row.Cells[5].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["Unit"] = ((TextBox)(row.Cells[6].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["IG"] = ((TextBox)(row.Cells[7].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["EXTQTY"] = ((TextBox)(row.Cells[8].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["CSTCD"] = ((TextBox)(row.Cells[9].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["PCOST"] = ((TextBox)(row.Cells[10].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["SCOST"] = ((TextBox)(row.Cells[11].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["ACOST"] = ((TextBox)(row.Cells[12].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["TCOST"] = ((TextBox)(row.Cells[13].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["ICOST"] = ((TextBox)(row.Cells[14].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["BIZCODE"] = ((TextBox)(row.Cells[16].Controls[0])).Text;
// dt.Rows[row.DataItemIndex]["DeleteItem"] = ((TextBox)(row.Cells[17].Controls[0])).Text;
//Reset the edit index.
GridView1.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
private void BindData()
{
GridView1.DataSource = Session["Sqldatasource1"];
GridView1.DataBind();