我正在用 gridview 做一些复杂的事情,而我和完成之间唯一的事情是我无法以编程方式设置数据绑定。除了我仍然无法更新数据源之外,我已经解决了这个问题。
我已经用一个依赖下拉列表替换了一个输入字段,并让它保留数据绑定上字段的值。我不能直接对它进行数据绑定,因为我得到“选定的值不在项目列表中”或其他东西,所以我必须找到一种方法来让网格或数据源从这个依赖下拉列表中获取值并将其应用到桌子。
有什么帮助吗?
<asp:GridView ID="gvManager" runat="server"
AutoGenerateColumns="False" DataSourceID="ldsCampaigns"
ondatabound="gvManager_DataBound"
onrowediting="gvManager_RowEditing" DataKeyNames="ContentID">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ContentID" HeaderText="ContentID"
SortExpression="ContentID" />
<asp:BoundField DataField="CampaignName" HeaderText="CampaignName"
SortExpression="CampaignName" />
<asp:BoundField DataField="CampaignTitle" HeaderText="CampaignTitle"
SortExpression="CampaignTitle" />
<asp:BoundField DataField="CampaignTagLine" HeaderText="CampaignTagLine"
SortExpression="CampaignTagLine" />
<asp:TemplateField HeaderText="CampaignData" SortExpression="CampaignData">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ldsTables"
DataTextField="CMSTables" DataValueField="CMSTables"
SelectedValue='<%# Bind("CampaignData") %>' onload="DropDownList1_Load">
</asp:DropDownList>
<asp:LinqDataSource ID="ldsTables" runat="server"
ContextTypeName="DataContext"
onselecting="ldsTables_Selecting" Select="new (CMSTables)"
TableName="CampaignTables">
</asp:LinqDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("CampaignData") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DataColumn"
SortExpression="DataColumn">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" style="margin-bottom: 0px"
SelectedValue='<%# Bind("DataColumn") %>' Visible="False">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# Bind("DataColumn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CampaignLink" HeaderText="CampaignLink"
SortExpression="CampaignLink" />
<asp:BoundField DataField="Sunrise" HeaderText="Sunrise"
SortExpression="Sunrise" />
<asp:BoundField DataField="Sunset" HeaderText="Sunset"
SortExpression="Sunset" />
<asp:BoundField DataField="OwnerID" HeaderText="OwnerID"
SortExpression="OwnerID" />
<asp:CheckBoxField DataField="Enabled" HeaderText="Enabled"
SortExpression="Enabled" />
</Columns>
</asp:GridView>