Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C数据网格更新函数_C#_Asp.net_Datagrid - Fatal编程技术网

C# C数据网格更新函数

C# C数据网格更新函数,c#,asp.net,datagrid,C#,Asp.net,Datagrid,目前,我在DataGrid的更新功能方面遇到了问题。无法在DataGrid中捕获我的输入。 有没有一种方法可以使用DataGrid捕获我的输入?因为互联网上的大多数信息都使用不同的GridView 编辑: 这是一个具有更新、编辑和删除功能的数据网格。 例如 我选择一行数据,按编辑按钮,填写所选行的数据,然后按更新按钮更新所选行信息。 在这种情况下,我无法在编辑后捕获所选行信息。 因此,我无法更新行数据 下面是HTML的代码 <asp:DataGrid ID="dgRecords"

目前,我在DataGrid的更新功能方面遇到了问题。无法在DataGrid中捕获我的输入。 有没有一种方法可以使用DataGrid捕获我的输入?因为互联网上的大多数信息都使用不同的GridView

编辑: 这是一个具有更新、编辑和删除功能的数据网格。 例如 我选择一行数据,按编辑按钮,填写所选行的数据,然后按更新按钮更新所选行信息。 在这种情况下,我无法在编辑后捕获所选行信息。 因此,我无法更新行数据

下面是HTML的代码

    <asp:DataGrid ID="dgRecords" runat="server" Width="100%" DataKeyField="InsitePriceID"
                    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="5"
                    OnPageIndexChanged="dgRecords_PageIndexChanged" OnSortCommand="dgRecords_SortCommand"
                      OnDeleteCommand="dgRecords_OnDelete" OnEditCommand="dgRecords_OnEdit" OnUpdateCommand="dgRecords_OnUpdate"
                       OnCancelCommand="dgRecords_OnCancel">
                    <AlternatingItemStyle CssClass="Data"></AlternatingItemStyle>
                    <ItemStyle CssClass="Data"></ItemStyle>
                    <HeaderStyle CssClass="ColHeader"></HeaderStyle>
                    <Columns>
                        <asp:BoundColumn Visible="False" DataField="InsitePriceID"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ServicePartFrom" HeaderText="No. of Service Part (From)"
                            SortExpression="ServicePartFrom"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ServicePartTo" HeaderText="No. of Service Part (To)"
                            SortExpression="ServicePartTo"></asp:BoundColumn>
                        <asp:BoundColumn DataField="BaseAmount" HeaderText="% from Base Amount" SortExpression="BaseAmount">
                        </asp:BoundColumn>
                        <asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" EditText="Edit"
                            UpdateText="Update"></asp:EditCommandColumn>
                        <asp:ButtonColumn ButtonType="PushButton" CommandName="Delete" Text="Delete"></asp:ButtonColumn>
                    </Columns>
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                </asp:DataGrid>
<td style="width: 1014px">
                <asp:Label ID="lbla" runat="server"></asp:Label>
                <asp:Label ID="lblb" runat="server"></asp:Label>
                <asp:Label ID="lblc" runat="server"></asp:Label>
            </td>

我用这种方法解决了这个问题

protected void dgRecords_OnUpdate(object source, DataGridCommandEventArgs e)
{
    if (e.CommandName == "Update")
    {
        string strInsitePriceID = dgRecords.DataKeys[e.Item.ItemIndex].ToString();
        TextBox temp, temp2, temp3;
        temp = (TextBox)e.Item.Cells[1].Controls[0];
        temp2 = (TextBox)e.Item.Cells[2].Controls[0];
        temp3 = (TextBox)e.Item.Cells[3].Controls[0];

        int intServicePartFrm = Int32.Parse(temp.Text);
        int intServicePartTo = Int32.Parse(temp2.Text);
        int fltPercentBaseAmt = Int32.Parse(temp3.Text);

能否指定无法捕获我的输入?这是否意味着您可以在那里获得默认值?那么我猜您是在回发上对DataGrid进行数据绑定。添加如果!IsPostBackBindDataGrid;是,我从数据库获得默认值显示,但我无法编辑行数据。我的更新函数有点问题。正如我在上一篇评论中提到的,我假设您也在回发中进行数据绑定。向我们展示您的页面加载。嗨,Tim Schmelter,如何为更新的行进行数据绑定?它位于BoundColumn字段而不是textbox字段中,所以我不知道如何对其进行数据绑定和更新。
protected void dgRecords_OnUpdate(object source, DataGridCommandEventArgs e)
{
    if (e.CommandName == "Update")
    {
        string strInsitePriceID = dgRecords.DataKeys[e.Item.ItemIndex].ToString();
        TextBox temp, temp2, temp3;
        temp = (TextBox)e.Item.Cells[1].Controls[0];
        temp2 = (TextBox)e.Item.Cells[2].Controls[0];
        temp3 = (TextBox)e.Item.Cells[3].Controls[0];

        int intServicePartFrm = Int32.Parse(temp.Text);
        int intServicePartTo = Int32.Parse(temp2.Text);
        int fltPercentBaseAmt = Int32.Parse(temp3.Text);