【发布时间】:2014-06-25 08:58:00
【问题描述】:
我正在尝试将下拉列表绑定到数据集,但在我的 DDL 中得到空值。当我单击编辑模式的一行时,DDL 不会绑定,因为我找不到它。为什么我找不到行下拉列表并绑定它们??
using (var scTyche = new SqlConnection(ConfigurationManager.ConnectionStrings["KondorConnectionConnectionString"].ConnectionString))
{
foreach (GridViewRow row in GridView1.Rows)
{
var ddl = (DropDownList)row.FindControl("DropDownListFolders1");
var da = new SqlDataAdapter();
var dt = new DataTable();
var ds = new DataSet();
scTyche.Open();
var cmdTyche = scTyche.CreateCommand();
cmdTyche.CommandType = CommandType.StoredProcedure;
cmdTyche.CommandText = "dbo.spGetFolders";
cmdTyche.CommandTimeout = 60;
cmdTyche.Parameters.Add("@nBranchId", SqlDbType.Int).Value = intBranchId;
da.SelectCommand = cmdTyche;
da.Fill(dt);
ds.Tables.Add(dt);
ddl.DataSource = ds;
ddl.DataTextField = "strShort";
ddl.DataValueField = "nId";
ddl.DataBind();
cmdTyche.Parameters.Clear();
scTyche.Dispose();
scTyche.Close();
}
}
我的aspx:
<asp:UpdatePanel runat="server" ID="update">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing"
AllowSorting="True" AutoGenerateColumns="False" SkinID="gridviewGridlinesSkin"
OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"
EmptyDataText="No positions found">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("strPositionId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Folder" SortExpression="strFolderName">
<EditItemTemplate>
<BrummerComp:SortableDropDownList ID="DropDownListFolders1" Width="141px" runat="server"
SkinID="BCdropdownlistSkin"/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
【问题讨论】:
-
您在哪种方法下运行第一个代码部分?