我将 Some Invoice No 表格添加到下拉列表中,在选择发票编号后,我可以将所有产品带到网格视图,包括附加、价格和所有,
我的问题是我必须单击两次才能编辑该行,但它没有更新,当第一次单击第一行中的编辑按钮时,它不起作用,但是单击下一行后,第一行的编辑按钮启用编辑文本框,但不只更新网格上的空数据......
图片 http://i.stack.imgur.com/X8W6Q.gif
在这部分中,我将数据带到网格中..
DataTable DataTbt = new DataTable();
SqlCommand Command = new SqlCommand();
SqlDataAdapter DtaAdapter = new SqlDataAdapter();
protected void ddlInvoiceNumber_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
GetReturnRecords("Invoice No", ddlInvoiceNumber.SelectedValue);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", String.Format("alert('Error occured : {0}');", ex.Message), true);
}
finally
{
DataTbt.Clear();
DataTbt.Dispose();
DtaAdapter.Dispose();
Command.Dispose();
Connection.Close();
}
}
private void GetReturnRecords(string searchBy, string searchVal)
{
try
{
Command = new SqlCommand("SP_SearchPurchasesLines", Connection);
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.AddWithValue("@SearchBy", searchBy);
Command.Parameters.AddWithValue("@SearchVal", searchVal);
DtaAdapter.SelectCommand = Command;
DtaAdapter.Fill(DataTbt);
if (DataTbt.Rows.Count > 0)
{
GridViewPurchaseReturn.DataSource = DataTbt;
GridViewPurchaseReturn.DataBind();
}
else
{
GridViewPurchaseReturn.DataSource = DataTbt;
GridViewPurchaseReturn.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", String.Format("alert('Error occured : {0}');", ex.Message), true);
}
finally
{
DataTbt.Clear();
DataTbt.Dispose();
Command.Dispose();
Connection.Close();
}
}
数据绑定到网格..
private void BindReturnGrid()
{
try
{
DtaAdapter = new SqlDataAdapter("SP_SearchPurchasesLines", Connection);
DtaAdapter.Fill(DataTbt);
if (DataTbt.Rows.Count > 0)
{
GridViewPurchaseReturn.DataSource = DataTbt;
GridViewPurchaseReturn.DataBind();
}
else
{
GridViewPurchaseReturn.DataSource = null;
GridViewPurchaseReturn.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
DataTbt.Clear();
DataTbt.Dispose();
DtaAdapter.Dispose();
Connection.Close();
}
}
编辑更新从网格中删除行...
protected void GridViewPurchaseReturn_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridViewPurchaseReturn.EditIndex = -1;
BindReturnGrid();
}
protected void GridViewPurchaseReturn_RowEditing(object sender, GridViewEditEventArgs e)
{
GridViewPurchaseReturn.EditIndex = e.NewEditIndex;
BindReturnGrid();
}