为什么我收到Specified参数超出了有效值的误差范围 [英] Why am I receiving Specified argument was out of the range of valid value error

查看:79
本文介绍了为什么我收到Specified参数超出了有效值的误差范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下asp.net代码:



 <      class   =  taskGridView      runat   =  server >  
< tr >
< td >
< asp:DropDownList ID < span class =code-keyword> = ddlTask​​Name CssClass = selected-select DataSourceID = dsPopulateTaskName AutoPostBack = true DataValueField = 任务名称 runat = server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlTask​​Name_onSelectIndexChanged >
< asp:ListItem 文本 = 全部 = > < / asp:ListItem >
< / asp:DropDownList >
< asp:SqlDataSource ID = dsPopulateTaskName runat = server ConnectionString = <% $ ConnectionStrings:gvCo nnString%> SelectCommand = > < / asp:SqlDataSource >
< ; / td >
< td >
< asp:DropDownList ID = ddlService CssClass = selected-select DataSourceID = dsPopulateService AutoPostBack = true DataValueField = 服务 runat = server 宽度 = 100% 字体-Size = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlService_onSelectIndexChanged >
< asp:ListItem 文本 = 所有 = > < / asp:ListItem >
< / asp:DropDownList >
< asp:SqlDataSource ID = dsPopulateService runat = 服务器 ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand = > < / asp:SqlDataSource >
< / td >
< td >
< asp:DropDownList < span class =code-attribute> ID = ddlStatus CssClass = selected-select DataSourceID = dsPopu lateStatus AutoPostBack = true DataValueField = 状态 runat = server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlStatus_onSelectIndexChanged >
< asp:ListItem 文本 = 所有 = > < / asp:ListItem >
< span class =code-keyword>< / asp:DropDownList >
< asp:SqlDataSource ID = dsPopulateStatus runat = server ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand = > < / asp:SqlDataSource >
< / td >
< td >
< asp:DropDownList ID = ddlDueDate CssClass = selected-select DataSourceID = dsPopulateDueDate AutoPostBack = true DataValueField = 截止日期 runat = < span class =code-keyword> server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlDueDate_onSelectIndexChanged >
< asp:ListItem 文字 = 全部 = > < / asp:ListItem >
< < span class =code-leadattribute> / asp:DropDownList >
< asp:SqlDataSource ID < span class =code-keyword> = dsPopulateD ueDate runat = server ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand = > < / asp:SqlDataSource >
< / td >
< < span class =code-leadattribute> td >
< asp:DropDownList ID = ddlOwner CssClass = selected-select DataSourceID = dsPopulateOwner AutoPostBack = true DataValueField = 所有者 运行at = server 宽度 = 100% < span class =code-attribute> 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlOwner_onSelectIndexChanged >
< asp:ListItem 文本 = 所有 = > < / asp:ListItem >
< / asp:DropDownList >
< asp:SqlDataSource ID = dsPopulateOwner runat = server ConnectionString = < ;% $ ConnectionStrings:gvConnString%> SelectCommand = > < / asp:SqlDataSource >
< / td >
< td >
< asp:DropDownList ID = ddlClient CssClass = selected-select DataSourceID = dsPopulateClient < span class =code-attribute> AutoPostBack = true DataValueField = 客户端 runat = server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlClient_onSelectIndexChanged >
< asp:ListItem 文字 = 所有 =
> < / asp:ListItem >
< / asp :DropDownList >
< asp:SqlDataSource ID = dsPopulateClient runat < span class =code-keyword> = server ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand = > < / asp:SqlDataSource >
< / td >
< td >
< asp:DropDownList ID = ddlSite CssClass = chos en-select DataSourceID = dsPopulateSite AutoPostBack = true DataValueField = 网站 runat = server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = < span class =code-keyword> ddlSite_onSelectIndexChanged >
< asp:ListItem 文本 = 所有 = > < / asp:ListItem >
& lt; / asp:DropDownList >
< asp:SqlDataSource ID = dsPopulateSite runat = server < span class =code-attribute> ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand = > &l t; / asp:SqlDataSource >
< / td >
< td >
< asp:DropDownList ID = ddlPractice CssClass = selected-select DataSourceID = < span class =code-keyword> dsPopulatePractice AutoPostBack = true DataValueField = < span class =code-keyword>练习 runat = server 宽度 = 100% 字体大小 = 11px AppendDataBoundItems = true OnSelectedIndexChanged = ddlPractice_onSelectIndexChanged >
< asp:ListItem 文本 = 所有 = < span class =code-keyword>% > < / asp:ListItem >
< / asp:DropDownList >
< ; asp:Sql DataSource ID = dsPopulatePractice runat = server ConnectionString = <% $ ConnectionStrings:gvConnString%> SelectCommand =\"\"></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID=\"ddlProvider\" CssClass=\"chosen-select\" DataSourceID=\"dsPopulateProvider\" AutoPostBack=\"true\" DataValueField=\"Provider\" runat=\"server\" Width=\"100%\" Font-Size=\"11px\" AppendDataBoundItems=\"true\" OnSelectedIndexChanged=\"ddlProvider_onSelectIndexChanged\">
<
asp:ListItem Text=\"All\" Value=\"%\"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID=\"dsPopulateProvider\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:gvConnString %>\" SelectCommand=\"\"></asp:SqlDataSource>
</td>
</tr>
</table>
<asp:GridView ShowHeaderWhenEmpty=\"false\" AlternatingRowStyle-BackColor=\"#EBE9E9\" AutoGenerateColumns=\"false\" OnSorting=\"yourTasksGV_Sorting\" AllowSorting=\"true\" ID=\"yourTasksGV\" runat=\"server\" ClientIDMode=\"Static\" EmptyDataText=\"You currently have no tasks assigned to you\" OnRowDataBound=\"yourTasksGV_RowDataBound\" OnRowCreated=\"yourTasksGV_RowCreated\">
<Columns>
<asp:HyperLinkField Target=\"_self\" DataNavigateUrlFields=\"Task Detail\" DataTextField=\"Task Name\" DataNavigateUrlFormatString=\"\" HeaderText=\"Task Detail\" SortExpression=\"Task Name\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Service\" HeaderText=\"Service\" SortExpression=\"Service\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Status\" HeaderText=\"Status\" SortExpression=\"Status\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Due Date\" HeaderText=\"Due\" SortExpression=\"Due Date\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Owner\" HeaderText=\"Owner\" SortExpression=\"Owner\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Client\" HeaderText=\"Client\" SortExpression=\"Client\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Site\" HeaderText=\"Site\" SortExpression=\"Site\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField
DataField=\"Practice\" HeaderText=\"Practice\" SortExpression=\"Practice\" ItemStyle-CssClass=\"taskTableColumn\" />
<asp:BoundField DataField=\"Provider\" HeaderText=\"Provider\" SortExpression=\"Provider\" ItemStyle-CssClass=\"taskTableColumn\" />
</Columns>
</asp:GridView>





code-behind:



protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView hGrid = (GridView)sender;
GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);


TableHeaderCell tcCellTask = new TableHeaderCell();
tcCellTask.Controls.Add(ddlTaskName);
gvrRow.Cells.Add(tcCellTask);
yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);

TableHeaderCell tcCellSvc = new TableHeaderCell();
tcCellSvc.Controls.Add(ddlService);
gvrRow.Cells.Add(tcCellSvc);
yourTasksGV.Controls[0].Controls.AddAt(1, gvrRow);

/*TableHeaderCell tcCellStats = new TableHeaderCell();
tcCellStats.Controls.Add(ddlStatus);
gvrRow.Cells.Add(tcCellStats);
yourTasksGV.Controls[0].Controls.AddAt(2, gvrRow);

TableHeaderCell tcCellDD = new TableHeaderCell();
tcCellDD.Controls.Add(ddlDueDate);
gvrRow.Cells.Add(tcCellDD);
yourTasksGV.Controls[0].Controls.AddAt(3, gvrRow);

TableHeaderCell tcCellOwner = new TableHeaderCell();
tcCellOwner.Controls.Add(ddlOwner);
gvrRow.Cells.Add(tcCellOwner);
yourTasksGV.Controls[0].Controls.AddAt(4, gvrRow);

TableHeaderCell tcCellCli = new TableHeaderCell();
tcCellCli.Controls.Add(ddlClient);
gvrRow.Cells.Add(tcCellCli);
yourTasksGV.Controls[0].Controls.AddAt(5, gvrRow);

TableHeaderCell tcCellSit = new TableHeaderCell();
tcCellSit.Controls.Add(ddlSite);
gvrRow.Cells.Add(tcCellSit);
yourTasksGV.Controls[0].Controls.AddAt(6, gvrRow);

TableHeaderCell tcCellPra = new TableHeaderCell();
tcCellPra.Controls.Add(ddlPractice);
gvrRow.Cells.Add(tcCellPra);
yourTasksGV.Controls[0].Controls.AddAt(7, gvrRow);

TableHeaderCell tcCellPro = new TableHeaderCell();
tcCellPro.Controls.Add(ddlProvider);
gvrRow.Cells.Add(tcCellPro);
yourTasksGV.Controls[0].Controls.AddAt(8, gvrRow);*/


LinkButton btnSort;
System.Web.UI.WebControls.Image image;
//iterate through all the header cells
foreach (TableCell cell in e.Row.Cells)
{
//check if the header cell has any child controls
if (cell.HasControls())
{
//get reference to the button column
btnSort = (LinkButton)cell.Controls[0];
image = new System.Web.UI.WebControls.Image();
if (ViewState[\"sortExp\"] != null)
{
//see if the button user clicked on and the sortexpression in the viewstate are same
//this check is needed to figure out whether to add the image to this heade column or not
if (btnSort.CommandArgument == ViewState[\"sortExp\"].ToString())
{
//check what type of sort order it is
if (ViewState [\"sortOrder\"].ToString() == \"Asc\")
{
image.ImageUrl = \"../theImages/up.png\";
image.CssClass = \"hdrImage\";
}
else
{
image.ImageUrl = \"../theImages/down.png\";
image.CssClass = \"hdrImage\";
}
cell.Controls.Add(image);
}
}
}
}
}
}





After creating the first two header cell, when it gets to the third and consequent one, I get an error stating: 

Specified argument was out of the range of valid values.

Parameter name: index

I have 9 columns in the GridView but I am not sure why I am receiving the error.

How do I resolve it?

If I uncomment everything, only three columns are created but I still get the same error.

解决方案

ConnectionStrings:gvConnString %>\" SelectCommand=\"\" ></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID=\"ddlService\" CssClass=\"chosen-select\" DataSourceID=\"dsPopulateService\" AutoPostBack=\"true\" DataValueField=\"Service\" runat=\"server\" Width=\"100%\" Font-Size=\"11px\" AppendDataBoundItems=\"true\" OnSelectedIndexChanged=\"ddlService_onSelectIndexChanged\">
<asp:ListItem Text=\"All\" Value=\"%\"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID=\"dsPopulateService\" runat=\"server\" ConnectionString=\"<%


ConnectionStrings:gvConnString %>\" SelectCommand=\"\"></asp:SqlDataSource> $ b$b </td>
<td>
<asp:DropDownList ID=\"ddlStatus\" CssClass=\"chosen-select\" DataSourceID=\"dsPopulateStatus\" AutoPostBack=\"true\" DataValueField=\"Status\" runat=\"server\" Width=\"100%\" Font-Size=\"11px\" AppendDataBoundItems=\"true\" OnSelectedIndexChanged=\"ddlStatus_onSelect IndexChanged\">
<asp:ListItem Text=\"All\" Value=\"%\"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID=\"dsPopulateStatus\" runat=\"server\" ConnectionString=\"<%


ConnectionStrings:gvConnString %>\" SelectCommand=\"\"></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID=\"ddlDueDate\" CssClass=\"chosen-select\" DataSourceID=\"dsPopulateDueDate\" AutoPostBack=\"true\" DataValueField=\" Due Date\" runat=\"server\" Width=\"100%\" Font-Size=\"11px\" AppendDataBoundItems=\"true\" OnSelectedIndexChanged=\"ddlDueDate_onSelectIndexChanged\">
<asp:ListItem
Text=\"All\" Value=\"%\"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID=\"dsPopulateDueDate\" runat=\"server\" ConnectionString=\"<%


I have the following asp.net code:

<table class="taskGridView"  runat="server">
    <tr>
        <td>
            <asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateTaskName" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlService" CssClass="chosen-select" DataSourceID="dsPopulateService" AutoPostBack="true" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlService_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateService" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlStatus" CssClass="chosen-select" DataSourceID="dsPopulateStatus" AutoPostBack="true" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlStatus_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateStatus" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlDueDate" CssClass="chosen-select" DataSourceID="dsPopulateDueDate" AutoPostBack="true" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlDueDate_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateDueDate" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlOwner" CssClass="chosen-select" DataSourceID="dsPopulateOwner" AutoPostBack="true" DataValueField="Owner" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlOwner_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateOwner" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlClient" CssClass="chosen-select" DataSourceID="dsPopulateClient" AutoPostBack="true" DataValueField="Client" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlClient_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateClient" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlSite" CssClass="chosen-select" DataSourceID="dsPopulateSite" AutoPostBack="true" DataValueField="Site" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlSite_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateSite" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlPractice" CssClass="chosen-select" DataSourceID="dsPopulatePractice" AutoPostBack="true" DataValueField="Practice" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlPractice_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulatePractice" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
        <td>
            <asp:DropDownList ID="ddlProvider" CssClass="chosen-select" DataSourceID="dsPopulateProvider" AutoPostBack="true" DataValueField="Provider" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlProvider_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="dsPopulateProvider" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
        </td>
    </tr>
</table>
<asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
    <Columns>
        <asp:HyperLinkField Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Service" HeaderText="Service" SortExpression="Service" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Due Date" HeaderText="Due" SortExpression="Due Date" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Site" HeaderText="Site" SortExpression="Site" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Practice" HeaderText="Practice" SortExpression="Practice" ItemStyle-CssClass="taskTableColumn" />
        <asp:BoundField DataField="Provider" HeaderText="Provider" SortExpression="Provider" ItemStyle-CssClass="taskTableColumn" />
    </Columns>
</asp:GridView>



code-behind:

protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        GridView hGrid = (GridView)sender;
        GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);


        TableHeaderCell tcCellTask = new TableHeaderCell();
        tcCellTask.Controls.Add(ddlTaskName);
        gvrRow.Cells.Add(tcCellTask);
        yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);

        TableHeaderCell tcCellSvc = new TableHeaderCell();
        tcCellSvc.Controls.Add(ddlService);
        gvrRow.Cells.Add(tcCellSvc);
        yourTasksGV.Controls[0].Controls.AddAt(1, gvrRow);

        /*TableHeaderCell tcCellStats = new TableHeaderCell();
        tcCellStats.Controls.Add(ddlStatus);
        gvrRow.Cells.Add(tcCellStats);
        yourTasksGV.Controls[0].Controls.AddAt(2, gvrRow);

        TableHeaderCell tcCellDD = new TableHeaderCell();
        tcCellDD.Controls.Add(ddlDueDate);
        gvrRow.Cells.Add(tcCellDD);
        yourTasksGV.Controls[0].Controls.AddAt(3, gvrRow);

        TableHeaderCell tcCellOwner = new TableHeaderCell();
        tcCellOwner.Controls.Add(ddlOwner);
        gvrRow.Cells.Add(tcCellOwner);
        yourTasksGV.Controls[0].Controls.AddAt(4, gvrRow);

        TableHeaderCell tcCellCli = new TableHeaderCell();
        tcCellCli.Controls.Add(ddlClient);
        gvrRow.Cells.Add(tcCellCli);
        yourTasksGV.Controls[0].Controls.AddAt(5, gvrRow);

        TableHeaderCell tcCellSit = new TableHeaderCell();
        tcCellSit.Controls.Add(ddlSite);
        gvrRow.Cells.Add(tcCellSit);
        yourTasksGV.Controls[0].Controls.AddAt(6, gvrRow);

        TableHeaderCell tcCellPra = new TableHeaderCell();
        tcCellPra.Controls.Add(ddlPractice);
        gvrRow.Cells.Add(tcCellPra);
        yourTasksGV.Controls[0].Controls.AddAt(7, gvrRow);

        TableHeaderCell tcCellPro = new TableHeaderCell();
        tcCellPro.Controls.Add(ddlProvider);
        gvrRow.Cells.Add(tcCellPro);
        yourTasksGV.Controls[0].Controls.AddAt(8, gvrRow);*/

        LinkButton btnSort;
        System.Web.UI.WebControls.Image image;
        //iterate through all the header cells
        foreach (TableCell cell in e.Row.Cells)
        {
            //check if the header cell has any child controls
            if (cell.HasControls())
            {
                //get reference to the button column
                btnSort = (LinkButton)cell.Controls[0];
                image = new System.Web.UI.WebControls.Image();
                if (ViewState["sortExp"] != null)
                {
                    //see if the button user clicked on and the sortexpression in the viewstate are same
                    //this check is needed to figure out whether to add the image to this heade column or not
                    if (btnSort.CommandArgument == ViewState["sortExp"].ToString())
                    {
                        //check what type of sort order it is
                        if (ViewState["sortOrder"].ToString() == "Asc")
                        {
                            image.ImageUrl = "../theImages/up.png";
                            image.CssClass = "hdrImage";
                        }
                        else
                        {
                            image.ImageUrl = "../theImages/down.png";
                            image.CssClass = "hdrImage";
                        }
                        cell.Controls.Add(image);
                    }
                }
            }
        }
    }
}



After creating the first two header cell, when it gets to the third and consequent one, I get an error stating:

Specified argument was out of the range of valid values.

Parameter name: index

I have 9 columns in the GridView but I am not sure why I am receiving the error.

How do I resolve it?

If I uncomment everything, only three columns are created but I still get the same error.

解决方案

ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource> </td> <td> <asp:DropDownList ID="ddlService" CssClass="chosen-select" DataSourceID="dsPopulateService" AutoPostBack="true" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlService_onSelectIndexChanged"> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="dsPopulateService" runat="server" ConnectionString="<%


ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource> </td> <td> <asp:DropDownList ID="ddlStatus" CssClass="chosen-select" DataSourceID="dsPopulateStatus" AutoPostBack="true" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlStatus_onSelectIndexChanged"> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="dsPopulateStatus" runat="server" ConnectionString="<%


ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource> </td> <td> <asp:DropDownList ID="ddlDueDate" CssClass="chosen-select" DataSourceID="dsPopulateDueDate" AutoPostBack="true" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlDueDate_onSelectIndexChanged"> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="dsPopulateDueDate" runat="server" ConnectionString="<%


这篇关于为什么我收到Specified参数超出了有效值的误差范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆