【发布时间】:2013-11-15 05:14:24
【问题描述】:
我在标题行中不断收到上述错误,这是没有意义的,因为我正在使用一个只有 5 条记录的示例表,并且每条记录都有一个下拉菜单中的值。
这是我用来声明下拉列表的代码。我在我的 SQL 数据源中加入了两个表,以反映我希望在网格视图中填充的内容,并根据需要隐藏列。我正在使用相同的数据源来填充下拉列表,任何帮助将不胜感激
<asp:DropDownList ID="DropDownListCurrency" runat="server"
CausesValidation="True" DataSourceID="GridView"
DataTextField="Currency" DataValueField="Currency_ID"
AppendDataBoundItems="True">
<asp:ListItem Value="0" Text="<Select>" Enabled="True"></asp:ListItem>
</asp:DropDownList>
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
GridViewRow row = GridView1.SelectedRow;
AccountNumber.Text = (string)row.Cells[0].Text;
....
DropDownListCurrency.SelectedValue = (string)row.Cells[8].Text;
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
【问题讨论】:
-
为什么你的
DataSource是GridView?这是DataTable的名字吗? -
请给我们看代码...
-
@Habib - 我刚刚命名了 DataSource GridView,所以我知道它的用途。原谅我。我对此完全陌生。数据表的名称是 GridView1。
-
@deathismyfriend 参见上面的代码。
标签: c# asp.net sql visual-studio-2010