0
我將數據庫中的數據綁定到gridview組合框值。以下是gridview和rowdatabound事件的編碼部分。bind dropdownlist返回空值
<asp:GridView ID="workingdaygrid" runat="server"
onrowdeleting="branchgrid_RowDeleting"
onrowediting="branchgrid_RowEditing"
onrowcancelingedit="branchgrid_RowCancelingEdit"
onrowupdating="branchgrid_RowUpdating" DataKeyNames="Workingday_id"
onpageindexchanged="workingdaygrid_PageIndexChanged" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False" onrowdatabound="workingdaygrid_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CancelImageUrl="~/images/Cancel.jpg"
DeleteImageUrl="~/images/delete.jpg" EditImageUrl="~/images/Edit.jpg"
UpdateImageUrl="~/images/update.jpg" ButtonType="Image"/>
<asp:BoundField DataField="Workingday_id" HeaderText="WorkingDayID" />
<asp:BoundField DataField="Working_date" HeaderText="WorkingDayID" />
<asp:BoundField DataField="Working_day" HeaderText="WorkingDayID" />
<asp:TemplateField HeaderText="WorkingdayType">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("Workingday_type") %>'></asp:Label></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="Workingdaytype" runat="server" Width="100px">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
和行數據綁定事件代碼是
protected void workingdaygrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dl = (DropDownList)e.Row.FindControl("Workingdaytype");
DataTable worktype = inter.bindworkdaytype();
dl.DataSource = worktype;
dl.DataTextField = "Workingday_type";
dl.DataValueField = "Time_id";
dl.DataBind();
}
}
在follwing線運行它使用defugger(F11)以下行 DropDownList的DL =(DropDownList的)e.Row時返回空值。的FindControl( 「Workingdaytype」);
你看過這篇文章嗎? http://stackoverflow.com/questions/8573260/cant-find-dropdown-list-in-rowdatabound-event –
...和另一個使用RowDataBound()而不是RowEditing()的例子:http://stackoverflow.com /問題/ 833490/gridview的行編輯動態綁定到一個-下拉列表 –