当我单击编辑按钮时,我想在 gridview 的特定单元格中编辑 TaskName 和 DueDate。任何人都可以提供一些我可以放在 if(e.CommandName == "Edit") 中的代码?
这是我在 Checklist.aspx.cs 中的代码:
protected void gvAddTask_RowCommand(object sender, GridViewCommandEventArgs e)
{    
    int i = int.Parse(e.CommandArgument.ToString());    
    string CheckListId = gvAddTask.Rows[i].Cells[0].Text;
    if(e.CommandName == "Edit")
    {
    }
    if (e.CommandName == "Del")
    {
        BlChecklist blChecklist = new BlChecklist();
        blChecklist.DeleteChecklist(int.Parse(gvAddTask.Rows[i].Cells[0].Text));
        gvAddTask.DataBind();
    }
}
这是我的网格视图代码:
<asp:GridView ID="gvAddTask" runat="server" AutoGenerateColumns="False" Width="100%"
EmptyDataText="There are no tasks!" GridLines="Horizontal" 
OnRowCommand="gvAddTask_RowCommand" DataSourceID="ObjectDataSource1" 
CellPadding="4" BackColor="White" BorderColor="#336666" 
BorderStyle="Double" BorderWidth="3px" style="margin-top: 0px">
<Columns>
<asp:BoundField DataField="CheckListId" HeaderText="CheckListId" 
HeaderStyle-HorizontalAlign="Left" ReadOnly="True">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="TaskName" HeaderText="TaskName" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="DueDate" HeaderText="DueDate" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:ButtonField  ButtonType="Button" CommandName="Edit" Text="Edit"/>
<asp:ButtonField ButtonType="Button" CommandName="Del" Text="Delete" />
</Columns>
</asp:GridView>