[英]Binding data to dropdownlist control which is an edittemplate for my gridview asp.net but the datasource is in code behind
所以我有一個gridview:
<asp:GridView ID="gvExamSched" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" PageSize="30" Width="1030px" AllowSorting="True" AllowPaging="True" OnRowDataBound="gvExamSched_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ItemStyle-Width="10%" ReadOnly="true"/>
<asp:BoundField DataField="FIRST_NAME" HeaderText="FIRST_NAME" SortExpression="FIRST_NAME" ReadOnly="true" />
<asp:BoundField DataField="MIDDLE_NAME" HeaderText="MIDDLE_NAME" SortExpression="MIDDLE_NAME" ReadOnly="true"/>
<asp:BoundField DataField="LAST_NAME" HeaderText="LAST_NAME" SortExpression="LAST_NAME" ReadOnly="true"/>
<asp:BoundField DataField="EXTN" HeaderText="EXTN" SortExpression="EXTN" ReadOnly="true"/>
<asp:BoundField DataField="OR #" HeaderText="OR #" SortExpression="OR #" />
<asp:BoundField DataField="DATE" HeaderText="DATE" SortExpression="DATE" ItemStyle-Width="15%" />
<asp:TemplateField HeaderText="TIME_FROM" SortExpression="TIME_FROM">
<EditItemTemplate>
<asp:DropDownList ID="ddlTimeFrom" runat="server" Width="80px"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TIME_FROM") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TIME_TO" HeaderText="TIME_TO" SortExpression="TIME_TO" />
<asp:BoundField DataField="ROOM" HeaderText="ROOM" SortExpression="ROOM" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
現在dropdownlist(ddlTimeFrom)它的數據來自代碼behin(c#),這是:
private void BindTime()
{
DateTime StartTime = DateTime.ParseExact("00:00", "HH:mm", null);
DateTime EndTime = DateTime.ParseExact("23:55", "HH:mm", null);
TimeSpan Interval = new TimeSpan(0,5,0);
ddlTimeFrom.Items.Clear();
ddlTimeTo.Items.Clear();
while (StartTime <= EndTime)
{
ddlTimeFrom.Items.Add(StartTime.ToShortTimeString());
ddlTimeTo.Items.Add(StartTime.ToShortTimeString());
StartTime = StartTime.Add(Interval);
}
ddlTimeFrom.Items.Insert(0, new ListItem("--Select--", "0"));
ddlTimeTo.Items.Insert(0, new ListItem("--Select--", "0"));
}
起初我沒有使用gridview所以我傾向於在page_load中為下拉列表中的項目調用BindTime()但是現在我需要使用gridview編輯它但我不知道怎么樣......它甚至可能嗎? 如果它不是那么我猜我只需要每次手動放置物品......提前謝謝!
處理GridView RowEditing事件並在那里執行自定義邏輯。 有關詳細信息,請參閱此內容: Gridview行編輯 - 動態綁定到DropDownList
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.