Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


XML
<%@ 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>
Posted
Comments
Arul R Ece 18-May-12 2:43am    
I want to load user name for Header Assign To from data base .

 
Share this answer
 
Comments
Oshtri Deka 18-May-12 3:29am    
This is good direction.
5.
Arul R Ece 18-May-12 4:14am    
Hi ..

I am not able to get the answer
deeptibansal 18-May-12 4:40am    
In the link I gave above the function "load_department()" is used to return the Data Table which contains the value to be bind to the dropdown in the griview. Now in the gridview event "GridView1_RowDataBound" that function is called and the resulting data table is bound to the dropdown. Hope this will be helpful.
Arul R Ece 18-May-12 4:44am    
When i use that link..
Can't find the control(dropuser)
deeptibansal 18-May-12 5:02am    
Are you using

DropDownList dp= (DropDownList )e.Row .FindControl ("dropuser");

?Please copy your code-behind code.
You have to find the control of that dropdown in code behind.
then bind that dropdown as usual you bind dropdown.

You can find Dropdown like:

DropDownList drp=GridView1.FindControl("dropstatus");


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();
 
Share this answer
 
v3
hello you can visit this url..............Accessing a DropDownList inside a GridView[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900