Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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# 如何更改GridView中的selectedIndex并进行更新_C#_Asp.net - Fatal编程技术网

C# 如何更改GridView中的selectedIndex并进行更新

C# 如何更改GridView中的selectedIndex并进行更新,c#,asp.net,C#,Asp.net,所以我有一个gridview: <asp:GridView ID="grv_existingEmployee" runat="server" AutoGenerateColumns="False" OnRowCommand="grv_existingEmployee_RowCommand" onrowcancelingedit="grv_existingEmployee_RowCancelingEdi

所以我有一个gridview:

            <asp:GridView ID="grv_existingEmployee" runat="server" AutoGenerateColumns="False"
                OnRowCommand="grv_existingEmployee_RowCommand" 
                onrowcancelingedit="grv_existingEmployee_RowCancelingEdit" 
                onrowdeleted="grv_existingEmployee_RowDeleted" 
                onrowdeleting="grv_existingEmployee_RowDeleting" 
                onrowediting="grv_existingEmployee_RowEditing">
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:Button ID="but_delete" runat="server" Text="Delete" CommandName="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
                            <asp:Button ID="but_edit" runat="server" Text="Edit" CommandName="Edit" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Button ID="but_cancel" runat="server" Text="Cancel" CommandName="Cancel" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
                        </EditItemTemplate>
                    </asp:TemplateField>
            </asp:GridView>
不幸的是,这并没有设置选定的索引,有什么想法吗

编辑:在进一步的测试中,他们确实会更改所选索引,但只会在第二次回发时更改。

因此结果是

grv_existingEmployee.SelectedIndex = currentRowIndex;
还不够,还需要添加以下内容:

grv_existingEmployee.EditIndex = currentRowIndex;

您的代码是否输入了这些if块?因为这看起来应该设置GridView的SelectedIndex。是的,他们肯定会输入if块,但不会更改。等等,他们确实更改了它,但我必须回发两次。你能显示你最初将GridView数据绑定到的代码吗?
grv_existingEmployee.EditIndex = currentRowIndex;