Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I have a scenario of a user and departments, user had to select and save his departs at time of registration,

and then on update it maybe edit by him, so, the problem is that on the update page, I want to set checked = true on list of user departs, which is populating from the user_info db

(=> checked = true on those only which was selected by user previously at the time of registration)

maybe its clear question, but if any confusion, I will clear it,

Thanks for Helping me...

--------------------------------------------------------------------------------------------------

I have one solution but again the problem is that,I am calling that function on pageLoad but it will not work on load, but when I refresh my page it will work fine, (I am Checking Through Item Value, because, I was saved that in database, instead of depart Name)
C#
try
    {
        sqlcon.Open();
        cmd = new SqlCommand("select d.id from _dept d left join user u on u.id = d.id where u.email = '" + Email + "' order by d.id;", sqlcon);
        reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            ListItem li = ChkStatus.Items.FindByValue(reader["id"].ToString());
            if (li != null)
            {
                li.Selected = true;
            }
        }
    }
    catch (Exception)
    {
        MessageBox.Show("Found Error in Selecting your depart!");
        Response.Redirect("user.aspx", false);
    }
    finally { sqlcon.Close(); }


User_Profile.aspx[^]
user_profile.aspx.cs[^]
Posted
Updated 30-Aug-13 19:45pm
v2
Comments
[no name] 30-Aug-13 7:18am    
Why do you say that it won't work on a page load? What is it that you think your messagbox is going to do in your web application?
Herman<T>.Instance 30-Aug-13 7:21am    
is that source set in the if (!Page.IsPostBack) ?
MustafaIqbal 30-Aug-13 16:55pm    
Oh Sorry, I forgot to mention that, if I can use if(!Page.IsPostBack){ CODE ], It will not do any thing, aslo nothing on refreh. As before, when I am refreshing after page load it select or set checked = true; to ListBoxItem.
MustafaIqbal 30-Aug-13 16:57pm    
Anyways, Its Not working for me, What Can I do? Please Help!
Herman<T>.Instance 3-Sep-13 4:55am    
do you reload the object in the page_load?

please check with making AutoPostBack Property of ChkStatus and ChkDeparts...I am check with it,It's work
 
Share this answer
 
v2
Comments
MustafaIqbal 31-Aug-13 7:47am    
Sorry Sir, Its Not Working For me. I set the property AutoPostBack = true and also I called it under if condition of !Page.IsPostback. But No Response.
I did't find any help full answer yet, any body please help me?????
 
Share this answer
 
check Postback property of check box is True or not
 
Share this answer
 
Comments
MustafaIqbal 30-Aug-13 16:57pm    
Its Not working for me, What Can I do? Please Help!

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