Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please provide a sample for Page_Init with drop down list

New to C#
Posted

Here's an example.
Was there anything specific you were looking to see?

C#
protected void Page_Init(object sender, EventArgs e)
{
    DropdownList.DataSource=GetData();
    DropdownList.DataTextField="TextColumn";
    DropdownList.DataValueField="ValueColumn";
    DropdownList.DataBind();
}
 
Share this answer
 
Comments
Member 10744248 5-Jun-14 6:36am    
</td>
<td bgcolor="#DDDDDD" class="style9">
<asp:DropDownList ID="ddl_Status" runat="server" Height="16px" TabIndex="12"
Width="183px">
<asp:ListItem>Active
<asp:ListItem>Non-Active

</td>
something like below
C#
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    DropDownList ddl= new DropDownList();
    ddl.ID = "ddl1";
    ddl.Items.Add("---select---");
    ddl.Items.Add("Item1");
    this.Controls.Add(ddl);
}
 
Share this answer
 
Comments
Member 10744248 5-Jun-14 6:25am    
The problem I am facing is that I have a drop down list on a form and each time the data is uploaded the value in the record which feeds into the control of the drop down list is not updated on the form.

for instant I have a drop down list with 2 options "Active" and "Inactive"

1. I have stored "Inactive" for a particular person, however each time I select the person from the gridview the drop down list doesn't change to "Inactive" but "Active" comes up

</td>
<td bgcolor="#DDDDDD" class="style9">
<asp:DropDownList ID="ddl_Status" runat="server" Height="16px" TabIndex="12"
Width="183px">
<asp:ListItem>Active
<asp:ListItem>Non-Active

</td>


Pls assist

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