Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
strSQL = "SELECT * FROM User_Reg WHERE User_ID='" + UserId + "'";
        DataTable dataTablerepeaterUserList = null;
        dataTablerepeaterUserList =objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];

C#
foreach (DataRow dr in dataTablerepeaterUserList.Rows)
        {          

            ddlTitle.SelectedItem.Text = dr["Title"].ToString();
        }

XML
<asp:DropDownList ID="ddlTitle" runat="server" CssClass="csstextbox" >
                       <asp:ListItem>Mr.</asp:ListItem>
                       <asp:ListItem>Mrs.</asp:ListItem>
                       <asp:ListItem>Miss.</asp:ListItem>
                        <asp:ListItem>Dr.</asp:ListItem>
                   </asp:DropDownList>


XML
if suppose  dr["Title"]=Dr.
then it is overwrite Mr. with Dr. and got result like.  | Dr.  |
                                           | Mrs. |
                                           | Miss.|
                                           | Dr.  |

i am passing User_ID from View_User.aspx to Create_User.aspx For edit user purpose using querystring..Id getting proper.. showing all correct fields in Create_User.aspx ....All control get correct data properly but when i populate title of current user then it overwrite with first item of dropdownlist.(I have only problem with Dropdownlist it is overwritten)
Posted
Updated 17-Apr-12 2:17am
v4
Comments
Sebastian T Xavier 17-Apr-12 8:06am    
what is your question? can you make it more clear?

C#
string s = dr["Title"].ToString(); 
ddlTitle.SelectedText = s;


You can do it in one line, I just did it like that to make it easier to read. This will throw an error if the string s is not in the list.
 
Share this answer
 
v2
Use selected value
ddlTitle.SelectedValue = dr["Title"].ToString();

change this line also
<asp:dropdownlist id="ddlTitle" runat="server" cssclass="csstextbox" xmlns:asp="#unknown">
                  <asp:listitem text="Mr." value="Mr."></asp:listitem>
                  <asp:listitem text="Mrs." value="Mrs."></asp:listitem>
                  <asp:listitem text="Miss." value="Miss.">Miss.</asp:listitem>
                  <asp:listitem text="Dr." value="Dr.">Dr.</asp:listitem>
</asp:dropdownlist>
 
Share this answer
 
try this, it should work....


C#
ddlTitle.SelectedItem = dr["Title"].ToString();
 
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