Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
i have dropdown list when i insert country from dropdown list it succesfully inserted but on next page i want to show same country which i inserted in db should display on dropdownlist but dropdownlist should locked.
Posted

C#
dropdownlist1.enabbled = false;
(at page load event of the next page.)

C#
dropdownlist1.Text = (retrieved country name from the database)
 
Share this answer
 
hi

create same code

in aspx page

XML
<asp:DropDownList ID="ddl_offic_depar" runat="server" CssClass="ddl_width" Style="border: 1px solid black;"
                                            DataTextField="dept_name" DataValueField="dept_id" AppendDataBoundItems="true">
                                            <asp:ListItem>--Select Department--</asp:ListItem>
                                        </asp:DropDownList>

in .cs page
<pre lang="cs">protected void Department()
    {
        DataTable dt = Display_Logic.display_department_logic();
        ddl_offic_depar.DataSource = dt;
        ddl_offic_depar.DataBind();
    }</pre>


in  display logic
<pre lang="cs">public static DataTable display_department_logic()
   {
       SqlCommand cmd = new SqlCommand();
       cmd.CommandText = &quot;display_department_sp&quot;;
       return Create_Command.ExecQuery(cmd);
   }</pre>




you are create same code in country and i create a ntire architecture
 
Share this answer
 
you can use one of client side state management technique. i.e querystring
Using querystrings, you can pass the data(in your case it's country that inserted in database) from one page to very next page though url.

ex:
http;//www.xxxx.com/default.aspx?countryName=India
or
http;//www.xxxx.com/default.aspx?countryId=12

here 12 is the Id, for country in database.
you can read the values from url using following code
C#
string countryName = Request.QueryString["countryName"];
// or
// If you know the id of the country, then again connect to Database and retrieve the value,
// But passsing the value in querystring is best way.. so that you can avoid unnecessary Database hits
int countryid = Convert.ToInt32(Request.QueryString["countryId"]);

If you mean locking the Dropdownlist is Disabling or read only.
C#
ddlCountry.SelectedValue = countryName;
ddlCountry.Enabled = false;

Hope it will helps you..
Happy coding :)
 
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