
<asp:TemplateFIEld headerText="DIEnstleistung" SortExpression="gutscheinbezeichnung" headerStyle-WIDth="20px"> <EditItemTemplate> <asp:HIDdenFIEld runat="server" Value='<%# Bind("gutscheinart_ID")%>' ID="HIDdenFIEldGutscheinartID"/> <asp:DropDownList ID="DropDownListDIEnstleistung" ClIEntIDMode="Static" runat="server" DataSourceID="ObjectDataSourceDropDown" DataValueFIEld="gutscheinbezeichnung"> </asp:DropDownList> <asp:ObjectDataSource ID="ObjectDataSourceDropDown" runat="server" SelectMethod="GetGutscheinArt" Typename="Gmos.Halbtax.admin.ClIEnt.WebGui.DataManager"></asp:ObjectDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label ID="LabelGutscheinbezeichnung" runat="server" Text='<%# Bind("gutscheinbezeichnung") %>'></asp:Label> </ItemTemplate> <headerStyle WIDth="20px" /></asp:TemplateFIEld> 如您所见,我的EditItemTemplate-FIEld中有一个名为DropDownListDIEnstleitung的DropDownList.
我也创建了这个活动:
protected voID GrIDVIEwLehrling_RowDataBound(object sender,GrIDVIEwRowEventArgs e){ DropDownList DropDownListDIEnstleistungBackEnd = (DropDownList)GrIDVIEwLehrling.Rows[GrIDVIEwLehrling.Selectedindex].FindControl("DropDownListDIEnstleistung"); HIDdenFIEld HIDdenFIEldGutscheinartIDBackEnd = (HIDdenFIEld)GrIDVIEwLehrling.Rows[GrIDVIEwLehrling.EditIndex].FindControl("HIDdenFIEldGutscheinartID");} Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
有什么建议?
解决方法 尝试使用以下代码:protected voID GrIDVIEwLehrling_RowDataBound(object sender,GrIDVIEwRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DaTarow) { if (e.Row.RowState == DataControlRowState.Edit) { DropDownList ddlBackEnd = (DropDownList)e.Row.FindControl("DropDownListDIEnstleistung"); HIDdenFIEld hdnBackEnd = (HIDdenFIEld)e.Row.FindControl("HIDdenFIEldGutscheinartID"); } }} 代码首先检查行的type.它必须是DaTarow,以便排除页脚和标题行.然后代码检查该行是否实际处于编辑模式.如果是这种情况,那么代码将获取在实际行上执行FindControl的控件.
总结以上是内存溢出为你收集整理的c# – RowDataBound中的FindControl – 事件以错误结束全部内容,希望文章能够帮你解决c# – RowDataBound中的FindControl – 事件以错误结束所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)