我已经阅读了本网站和其他网站上的其他问题,但其中没有一个有效。我的EXPLAIN ANALYSE
中有两列,在点击编辑链接时应该成为GridView
。他们确实变成DropDownList
但从未获得任何数据。我确实放了一个DropDownList
,但这也没有给我任何帮助。我试图通过使用另一个函数显式绑定它,但我一直没有返回任何值。这是我的代码:
ASPX:
RowDataBound
代码背后:
<asp:GridView ID="dgvGameFIFolderMaintenance" runat="server" AutoGenerateColumns="false"
CssClass="ReportDataGrid" HeaderStyle-CssClass="DataGridHeader" FooterStyle-CssClass="NoShade"
RowStyle-CssClass="AccentShade" AlternatingRowStyle-CssClass="NoShade" SelectedRowStyle-CssClass="AccentLvl3"
PagerSettings-Mode="NumericFirstLast" PagerStyle-HorizontalAlign="Center" PagerStyle-CssClass="paging"
PageSize="25" AllowSorting="false" ShowFooter="true" ShowHeaderWhenEmpty="true" AllowPaging="true"
Width="900px" OnRowCancelingEdit="CancelEditRecord" OnRowEditing="EditRecord" OnRowUpdating="UpdateRecord">
<Columns>
<asp:TemplateField HeaderText="Account ID" ItemStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblAccountID" runat="server" Text='<%#Eval("Account_ID")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAccountID" runat="server" Text='<%#Eval("Account_ID")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAccountIDFT" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="File Type" ItemStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblFileType" runat="server" Text='<%#Eval("FileType")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblFileType" runat="server" Text='<%#Eval("FileType")%>' Visible="false"></asp:Label>
<asp:DropDownList ID="ddlFileType" runat="server"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFileTypeFT" runat="server" Width="98%"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Drop Location" ItemStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblDropLocation" runat="server" Text='<%#Eval("DropLocation")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDropLocation" runat="server" Text='<%#Eval("DropLocation")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDropLocationFT" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product" ItemStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblProduct" runat="server" Text='<%#Eval("Product")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblProduct" runat="server" Text='<%#Eval("Product")%>' Visible="false"></asp:Label>
<asp:DropDownList ID="ddlProduct" runat="server"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlProductFT" runat="server" Width="98%"></asp:DropDownList>
</FooterTemplate>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="retrun confirm('Are you sure you want to delete?');"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" CommandName="AddNew" Text="Add" OnClick="AddNewRecord" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" HeaderText="Edit" EditText="Edit" />
</Columns>
</asp:GridView>
答案 0 :(得分:0)
Dim ddLFileType As DropDownList = TryCast(dgvGameFIFolderMaintenance.FooterRow.FindControl("ddLFileType"), DropDownList)
Dim ddLProduct As DropDownList = TryCast(dgvGameFIFolderMaintenance.FooterRow.FindControl("ddLProduct"), DropDownList)
在编辑项目模板中声明页脚时,您正在寻找页脚中的ddLProduct
和ddLFileType
。
在你的RowDataBound中,你应该只能切换到使用当前行。
Dim ddLFileType As DropDownList = TryCast(e.Row.FindControl("ddLFileType"), DropDownList)
Dim ddLProduct As DropDownList = TryCast(e.Row.FindControl("ddLProduct"), DropDownList)