双网格视图';s选定的indexchanged事件不起作用

本文关键字:indexchanged 事件 不起作用 视图 网格 | 更新日期: 2023-09-27 17:57:37

我在一个页面中设置了两个Gridview。一个选定的索引更改了事件的加载另一个事件。但是,第二个网格的selectedindexchanged事件与第一个网格的select edindexchanged事件相同。我能做什么?我的函数名称是正确的。没有任何冲突。

这里是我的asp代码:

<asp:GridView ID="gdv" runat="server" 
                AutoGenerateColumns="False" onrowdatabound="gdv_RowDataBound" 
                onselectedindexchanged="gdv_SelectedIndexChanged" AllowPaging="True" 
                Width="100%" onpageindexchanging="gdv_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="Sl" HeaderStyle-HorizontalAlign="Center" 
                        HeaderText="SL #" ItemStyle-HorizontalAlign="Center">
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                    </asp:BoundField>
                    <asp:BoundField DataField="SalesOrderNo" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Order No" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="SectionID" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Section Id" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="SectionName" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Section Name" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="OutletID" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Outlet Id" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="OutletName" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="outlet Name" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="SalesPersonID" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Sales Person Name" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="OrderDate" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Order Date" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="OrderValue" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Order Value" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                   <asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <asp:CheckBox ID="checkOrderList" runat="server" ValidationGroup="ValCheckOrder" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                       <ItemTemplate>
                    <%--<asp:LinkButton ID="btnView" Text="View" runat="server" CommandName="ViewIndividualOrder" />--%>
                     <asp:Button ID="btnViewOrder" runat="server" Text="View" ValidationGroup="ValCheckOrder"
                        CommandName="ViewIndividualOrder" OnClick="btnViewOrder_Click" />
                </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle HorizontalAlign="Center" />
            </asp:GridView>
<asp:GridView ID="gdvOrderDetail" runat="server" 
                AutoGenerateColumns="False" onrowdatabound="gdvOrderDetail_RowDataBound" 
                onselectedindexchanged="gdvOrderDetail_SelectedIndexChanged" AllowPaging="True" 
                Width="100%" onpageindexchanging="gdvOrderDetail_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="Sl" HeaderStyle-HorizontalAlign="Center" 
                        HeaderText="SL #" ItemStyle-HorizontalAlign="Center">
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ProductID" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Product ID" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ProductName" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Product Name" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="UnitID" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Unit" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="PacketSize" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Packet Size" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
               <asp:TemplateField HeaderText="Sales Rate" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                     <asp:Label ID="lblSalesRate" runat="server" Text='<%# Eval("SalesRate") %>' Font-Size="Smaller" />
                </ItemTemplate>
            </asp:TemplateField>
                   <%-- <asp:BoundField DataField="SalesRate" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Sales Rate" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>--%>
                    <asp:BoundField DataField="OrderQty" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Order Qty" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>
              <asp:TemplateField HeaderText="MemoQty" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:TextBox ID="txtMemoQty" runat="server" Font-Bold="True" Width="100px" OnTextChanged="txtMemoQty_TextChanged"
                        AutoPostBack="true" Enabled="true" onkeypress="return onlyNumbers();"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorMemoQTY" ValidationGroup="ValCheckOrderDetail"
                        runat="server" ControlToValidate="txtMemoQty" ErrorMessage="*" Font-Size="X-Large"
                        ForeColor="Red"></asp:RequiredFieldValidator>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Amount" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                     <asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Amount") %>' Font-Size="Smaller" />
                </ItemTemplate>
            </asp:TemplateField>
                    <%--<asp:BoundField DataField="Amount" HeaderStyle-HorizontalAlign="Left" 
                        HeaderText="Amount" ItemStyle-HorizontalAlign="Left">
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle HorizontalAlign="Left" />
                    </asp:BoundField>--%>
                   <asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <asp:CheckBox ID="checkOrderList" runat="server" ValidationGroup="ValCheckOrderDetail" />
                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>
                <PagerStyle HorizontalAlign="Center" />
            </asp:GridView>

C#代码:

protected void gdv_SelectedIndexChanged(object sender, EventArgs e)
{
    int indx = 0;
    indx = gdv.SelectedIndex;
    string salesorderno = "";
    string sectionid = "";
    string sectionname = "";
    string outletid = "";
    string outletname = "";
    string salespersonname = "";
    string orderdate = "";
    string ordervalue = "";
    string ordercheck = "";
    for (int i = 0; i < 1; i++)
    {
        salesorderno = gdv.Rows[indx].Cells[1].Text.ToString();
        sectionid = gdv.Rows[indx].Cells[2].Text.ToString();
        sectionname = gdv.Rows[indx].Cells[3].Text.ToString();
        outletid = gdv.Rows[indx].Cells[4].Text.ToString();
        outletname = gdv.Rows[indx].Cells[5].Text.ToString();
        salespersonname = gdv.Rows[indx].Cells[6].Text.ToString();
        orderdate = gdv.Rows[indx].Cells[7].Text.ToString();
        ordervalue = gdv.Rows[indx].Cells[8].Text.ToString();
        ordercheck = gdv.Rows[indx].Cells[9].Text.ToString();
    }
    lblOrderNo.Text = salesorderno;
    lblSectionName.Text = sectionname;
    lblOutletName.Text = outletname;
    lblOrderDate.Text = orderdate;
    LoadOrderReportDetailGrid(salesorderno);
}
protected void gdvOrderDetail_SelectedIndexChanged(object sender, EventArgs e)
{
}

双网格视图';s选定的indexchanged事件不起作用

测试就足以知道事件的起源。示例:

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if(dataGrid1.SelectedItem!=null)
                MessageBox.Show("aaaaaaaaaaa");
        }
        private void dataGrid2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dataGrid2.SelectedItem != null)
                MessageBox.Show("BBBBBbbBBBB    ");
        }

只需打开网格视图的事件窗口,然后选择其中一个,然后在事件窗口上双击"selected index changed"事件。它将把您移到代码部分。如果您在true过程中,则事件绑定为true。如果没有,您必须更改程序的定义。

这是一个简单的过程。

  1. 复制过程中的代码并将其粘贴到安全的地方
  2. 删除与网格视图相关的过程
  3. 检查事件页面中的gridview,以确保"selectedindexchanged"事件中没有任何内容
  4. 双击第一个gridviews"selected index changed"事件。它将创建一个空白过程。将相关代码粘贴到此处
  5. 第二次也一样

另一件事是在属性窗口中检查网格视图的验证组。它们应该不同:)

NOT:请原谅我不能直接写代码。因为我没有自己的电脑。我希望它能起作用。