本文介绍了网格视图内的下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Friends ,,,
我有一个网格视图,并且在网格视图的下拉列表中.
我想从数据库中加载下拉列表(用户名)的数据.
我该怎么办.
Hi Friends,,,
I have a grid view and inside the grid view Dropdown list there.
I want load data for dropdown list (username) from data base.
How can i do.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Viewstatus.aspx.cs" Inherits="Viewstatus" %>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<%@ Register Src="include/Menu.ascx" TagName="Menu" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table align="center">
<tr>
<td>
<uc1:Menu ID="Menu1" runat="server" />
</td>
</tr>
</table>
<table cellpadding=2 width=100%>
<tr>
<td align="center">
<asp:GridView ID="grid" CssClass="grid" runat="server"
AutoGenerateColumns="False" onrowcancelingedit="grid_RowCancelingEdit"
onrowdeleting="grid_RowDeleting" onrowediting="grid_RowEditing"
onrowupdating="grid_RowUpdating" onrowdatabound="grid_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="Task ID">
<ItemTemplate>
<asp:Label ID="lbltaskid" runat="server" Text='<%#Bind("taskid")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txttaskid" runat="server" Text='<%#Bind("taskid")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Name">
<ItemTemplate>
<asp:Label ID="lbltask" runat="server" Text='<%#Bind("task")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txttask" runat="server" Text='<%#Bind("task")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Requester">
<ItemTemplate>
<asp:Label ID="lblreq" runat="server" Text='<%#Bind("reqfor")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtreq" runat="server" Text='<%#Bind("reqfor")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned To">
<ItemTemplate>
<asp:Label ID="lblasn" runat="server" Text='<%#Bind("Asssto")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dropuser" runat="server" DataTextField ='<%#Bind("Asssto")%>'></asp:DropDownList>
<%-- <asp:TextBox ID="txtreq" runat="server" Text='<%#Bind("Asssto")%>'></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Time">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%#Bind("datetime")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtdate" runat="server" Text='<%#Bind("datetime")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Estimated Time">
<ItemTemplate>
<asp:Label ID="lblest" runat="server" Text='<%#Bind("esttime")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtest" runat="server" Text='<%#Bind("esttime")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblsta" runat="server" Text='<%#Bind("status")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dropstatus" runat="server" DataValueField='<%#Bind("status")%>' >
<asp:ListItem Text="Open" Value="Open" > </asp:ListItem>
<asp:ListItem Text="Fixed" Value="Fixed"></asp:ListItem>
<asp:ListItem Text="Processing" Value="Processing"></asp:ListItem>
</asp:DropDownList>
<%-- <asp:TextBox ID="txtreq" runat="server" Text='<%#Bind("Asssto")%>'></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="50px" HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lbtnedit" runat="server" ForeColor="#0C4375" Text="Edit" CommandName="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbtnupdate" runat="server" ForeColor="#0C4375" Text="Update"
CommandName="Update"></asp:LinkButton>
<asp:LinkButton ID="lbtncancel" runat="server" ForeColor="#0C4375" Text="Cancel"
CommandName="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="50px" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" runat="server" ForeColor="#0C4375" Text="Delete"
CommandName="Delete"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Wrap="True" />
<ControlStyle BackColor="#EAF6FE" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
推荐答案
DropDownList drp=GridView1.FindControl("dropstatus");
现在drp是位于GridView内的DropDown.
现在绑定drp.
喜欢
Now drp is your DropDown which is inside GridView.
Now bind drp.
like
if ds contain your dataset with records then
drp.DataTextField="Name";
drp.DataValueField="1"
drp.DataSource=ds;
drp.DataBind();
这篇关于网格视图内的下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!