net gridview,我不希望使用内置控件,并希望在c#中手动绑定数据。有人可以让我知道从哪里开始,我如何使用3个不同的下拉菜单来添加更多过滤?
asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvContactorRowDataBound" Gridlines="Vertical" >
<Columns >
<asp:TemplateField HeaderText="Full Name" SortExpression="contactname" HeaderStyle-BackColor="deepskyblue">
<EditItemTemplate>
<asp:TextBox ID="txtcontactname2" runat="server" Text='<%# Bind("contactname") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorcontactname2" runat="server" ErrorMessage="Full Name is required for contractor update!" Text="*" ForeColor="Red" ControlToValidate="txtcontactname2" display="none"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcontactname2" runat="server" Text='<%# Bind("contactname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="phone" HeaderText="Phone" SortExpression="phone" HeaderStyle-BackColor="deepskyblue"/>
<asp:BoundField DataField="email" HeaderText="Email" SortExpression="email" HeaderStyle-BackColor="deepskyblue"/>
答案 0 :(得分:0)
您没有提及您的方案,因此我假设您希望在网格视图中显示所有学生,并且在每行中都有一个下拉菜单以选择教师。您有另一个数据库Teachers
,每位教师都有Id
和Name
。所以在你的代码背后,你收集了所有的老师:
protected List<teacher> teachers;
在Students
gridview的每一行中,您必须拥有此列:
<asp:TemplateField HeaderText="Teacher">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="selectClip" DataSource="<%# teachers %>"
DataTextField="Name" DataValueField="Id" AppendDataBoundItems="true">
<asp:ListItem Text="<---Select Teacher--->"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblShowTeacher" runat="server" Text='<%# Bind("Teacher") %>' />
</ItemTemplate>
</asp:TemplateField>
如果您想让教师加入SqlDataSource
,请更改此信息:
DataSource="<%# teachers %>
:DataSourceId="teachersDataSourceId"