gpt4 book ai didi

mysql - 从存储过程填充下拉列表错误: was out of range of valid values

转载 作者:行者123 更新时间:2023-11-29 18:47:00 25 4
gpt4 key购买 nike

出于某种原因,我的 DataGrid 中的下拉列表给出了错误:

Specified argument was out of the range of valid values.
Parameter name: index

来自行:

 CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataSource = rdr

我以前见过这个代码设置工作,所以不确定我错过了什么。我的 templateColumn 是 DataGrid 中的第二列。

Vb.net

Sub dg_Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
fillGroups()
End sub

Sub fillGroups()

Using con2 As New MySqlConnection

con2.ConnectionString = GetconnString(strFloor, lblDB.Text)

Dim cmd2 As New MySqlCommand()
con2.Open()
cmd2.Connection = con2
cmd2.CommandText = "stp_Select_GroupNames"

cmd2.CommandType = System.Data.CommandType.StoredProcedure

Dim rdr As MySqlDataReader

rdr = cmd2.ExecuteReader

CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataSource = rdr
CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataValueField = "ID"
CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataTextField = "GroupName"
CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataBind()
rdr.Close()
con2.Close()
End Using
End sub

ASP.net

<asp:TemplateColumn HeaderText="'Group'" ItemStyle-Width="225" FooterStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<FooterTemplate>
<asp:DropDownList ID="ddlAddGroup" runat="server" />
</FooterTemplate>
<ItemTemplate>
<%#Container.DataItem("GroupName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlEditGroup" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

更新

存储过程

CREATE DEFINER=`root`@`%` PROCEDURE `stp_Select_GroupNames`()
BEGIN
SELECT ID, GroupName from tblg;
END

当我从存储过程运行数据集时,我返回一个计数,这样我就知道我也得到了返回的记录。

最佳答案

当前解决方法:

因此,要填充页脚,您可以使用:

Sub fillAddGroups()
Dim ds As DataSet = getGroups()
Dim dd As DropDownList = CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList)
dd.DataSource = ds
dd.DataValueField = "ID"
dd.DataTextField = "GroupName"
dd.DataBind()
End Sub

要填充单击编辑按钮后显示的下拉列表,请执行以下操作:

Sub dg_Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
Dim intempId As Integer
Dim strGroup As String = ""
intempId = CType(e.Item.Cells(0).FindControl("lblEmployeeNumber"), Label).Text
strGroup = CType(e.Item.Cells(0).FindControl("lblGroup"), Label).Text
dgAdmins.EditItemIndex = e.Item.ItemIndex
sdsGroups.ConnectionString = GetconnString(strF, lblDB.Text)
ShowEmpTable(intempId)
fillAddGroups()
End Sub

其中 sdsGroups 是 HTML 中的 SqlDataSource:

<asp:SqlDataSource ID="sdsGroups"
ProviderName="MySql.Data.MySqlClient" SelectCommandType="StoredProcedure" SelectCommand="stp_Select_FloortblGroupNames" runat="server" />

Gridview修改

<asp:TemplateColumn HeaderText="'Group'" ItemStyle-Width="225" FooterStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<FooterTemplate>
<asp:DropDownList ID="ddlAddGroup" runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblGroup" Text='<%#Container.DataItem("GroupName")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlEditGroup" runat="server" DataSourceID="sdsGroups" DataTextField="GroupName" DataValueField="ID"/>
</EditItemTemplate>
</asp:TemplateColumn>

关于mysql - 从存储过程填充下拉列表错误: was out of range of valid values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com