页面启用gridview时,显示问题

时间:2012-03-18 13:22:20

标签: asp.net

我有以下gridview

<asp:GridView ID="importErrors" runat="server" AutoGenerateColumns="False" 
                DataSourceID="SqlDataSource_Errors" OnRowDataBound="gvErrors_CrossSale" PersistedSelection="True"                   
                AllowSorting="True" PageSize="3" AllowPaging="True">
                <Columns>
                    <asp:BoundField DataField="ccId" HeaderText="ccId" ReadOnly="True" 
                        SortExpression="ccId" >
                    <HeaderStyle ForeColor="#FF0066" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="custId" HeaderText=" ID " ReadOnly="True"
                        SortExpression="custId"  >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="idCampaign" HeaderText="Кампања ID" ReadOnly="True" 
                        SortExpression="idCampaign" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:CheckBoxField DataField="Kontaktiran" HeaderText="Контактиран" 
                        ReadOnly="True" SortExpression="Kontaktiran" >
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:CheckBoxField>
                    <asp:BoundField DataField="datumKontaktiran" HeaderText="Датум" 
                        ReadOnly="True" SortExpression="datumKontaktiran" 
                        DataFormatString="{0:d}" />
                    <asp:BoundField DataField="idKomentar" HeaderText="Коментар ID" ReadOnly="True" 
                        SortExpression="idKomentar" >
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Zabeleska" HeaderText="Забелешка" ReadOnly="True" 
                        SortExpression="Zabeleska" >
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="custFilijala" HeaderText="Филијала" 
                        ReadOnly="True" SortExpression="custFilijala" >
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource_Errors" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CrossSaleConnectionString %>" 
                SelectCommand="sp_ImportErrors" SelectCommandType="StoredProcedure">
            </asp:SqlDataSource>

是启用页面和以下事件处理程序 受保护的子gvErrors_CrossSale(ByVal sender As Object,ByVal e As GridViewRowEventArgs)

    If e.Row.Cells(1).Text.Equals("-1") Then
        e.Row.Cells(1).ForeColor = Drawing.Color.Red
    End If
    If e.Row.Cells(4).Text.Equals("01/01/1900") Then
        e.Row.Cells(4).ForeColor = Drawing.Color.Red
    End If
    Dim csObj As New CrossSaleMethods()
    If e.Row.Cells(5).Text.Equals("-1") Or csObj.ExistsInKomentari(e.Row.Cells(5).Text) Then
        e.Row.Cells(5).ForeColor = Drawing.Color.Red
    End If
End Sub

失败如下:“指定的参数超出了有效值的范围。 参数名称:index“当我将gridview设置为启用了pagged时,否则我没有这个问题?

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

检查DataControlRowType.DataRow上的e.Row.RowType。您可能会在没有Cell(5)等的寻呼机行上获得异常。