Я пытаюсь использовать GridViewCommandEventArgs
в виде сетки, но при запуске он продолжает говорить: обновление не поддерживается источником данных 'SqlDataSource1', если не указан параметр UpdateCommand.
У меня есть несколько Linkbuttons
в сетке, следовательно, OnRowCommand
OnRowCommand = "Grid_Row"
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Update" CommandArgument='<%#Eval("Serno") %>' runat="server" OnClientClick="return confirm('Are you sure you want to Update this?');" CommandName ="Update" >Update</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Remove" CommandArgument='<%#Eval("Serno") %>' runat="server" OnClientClick="return confirm('Are you sure you want to Remove this Item?');" CommandName ="Remove" >Remove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
protected void Grid_Row(Object sender, GridViewCommandEventArgs e)
{
LinkButton Remove = (LinkButton)GridView1.FindControl("Remove");
LinkButton Update = (LinkButton)GridView1.FindControl("Update");
if (e.CommandName == "Remove")
{
try
{
int index = Convert.ToInt32(e.CommandArgument);
SqlConnection con = new SqlConnection(Constring);
con.Open();
SqlCommand cmd = new SqlCommand(" update [Order_Items] set status=0 WHERE [Serno] =" + index.ToString() + "", con);
if (cmd.ExecuteNonQuery() > 0)
{
GridView1.DataBind();
msg_lbl.Text = "Record Deleted";
}
else
{
}
con.Close();
}
catch
{
}
}
else if (e.CommandName == "Update")
{
try
{
int index = Convert.ToInt32(e.CommandArgument);
[Convert.ToDouble(e.CommandArgument)].FindControl("Quantity");
GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
string Q = ((TextBox)clickedRow.FindControl("Quantity_Txt") as TextBox).Text;
string P = ((Label )clickedRow.FindControl("Amount_Lbl") as Label ).Text;
double Quantity = Convert.ToDouble(Q);
double Price = Convert.ToDouble(P);
double Calc = Quantity * Price;
SqlConnection con = new SqlConnection(Constring);
con.Open();
SqlCommand cmd = new SqlCommand("update [Order_Items] set Quantity='"+Quantity +"', Money='" + Calc + "' WHERE [Serno] =" + index.ToString() + "", con);
if (cmd.ExecuteNonQuery() > 0)
{
GridView1.DataBind();
msg_lbl.Text = "Record Updated";
}
else
{
}
con.Close();
}
catch
{
}
}
}