Link to home
Start Free TrialLog in
Avatar of Romacali
Romacali

asked on

dynamic ddl

HI,

I have a ddl in my page that should get the values from the database table type?
I'm new to ASP.net
how can I add it to my page?

so far I hardcode as:
<asp:DropDownList ID="ddlEvaluationType" runat="server" CssClass="ddl">
                    <asp:ListItem Value="1" >Program Begin</asp:ListItem>
                    <asp:ListItem Value="2" >Program End</asp:ListItem>
                    <asp:ListItem Value="3" >6 Months</asp:ListItem>
                    </asp:DropDownList>

Open in new window

Avatar of marktoth
marktoth

There are a few ways to do this.  
You can use an sqldatasource control placed directly on the aspx page
OR
you can use the code behind file to retrieve data from the database, set the ddl's datasource property and call databind() on the dropdown list

Which way do you want to know?
Avatar of Romacali

ASKER

I think the  sqldatasource control placed directly on the aspx page is easier :)

thanks
ASKER CERTIFIED SOLUTION
Avatar of marktoth
marktoth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will try it out
ok..

now the value is not saving.. Now can I save it?

I had this code:
     cmd3.Parameters.Add(new SqlParameter("@EvaluationID", ddlEvaluationType.SelectedValue));
I would have to see your code for saving.
Actually looking at it.  You probably need to convert the selected value to an integer type for your save.
It's important that you match your database datatype to the type you're passing to your stored proc.
More than likely your storing the EvaluationTypeId as an integer in the database. ddlEvaluationType.SelectedValue returns a type string so convert.
cmd3.Parameters.Add(new SqlParameter("@EvaluationID", Convert.ToInt32(ddlEvaluationType.SelectedValue));