Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<asp:DropDownList ID="mainsubject" runat="server" Width="200px">
                                    <asp:ListItem>Select Topic</asp:ListItem>
                                    <asp:ListItem>Music</asp:ListItem>
                                    <asp:ListItem>Entertainment</asp:ListItem>
                                    <asp:ListItem>Sports</asp:ListItem>
                                    <asp:ListItem>Politics</asp:ListItem>
                                    <asp:ListItem>General</asp:ListItem>
                                    </asp:DropDownList>


In the above code i am using this dropdownlist as the main subject which on selection should display the values of the data repeaters based on the selected values.

C#
string quryAddBlog = "select sno,title, image, body, date, time from Blog_tb where subject='" + mainsubject.SelectedItem.Text.Trim() + "' order by sno desc";
        adp1 = new SqlDataAdapter(quryAddBlog, con);
        adp1.Fill(dt1);
        Repeater1.DataSource = dt1;
        Repeater1.DataBind();

The selected value of the dropdownlist is not selecting the subject column value from the database.

any suggestions will help me a lot.
thanks in advance
Posted
Updated 25-Jan-12 0:40am
v2
Comments
That's Aragon 25-Jan-12 6:56am    
Code looks good to me. Make sure that Dropdown binding is only happening one time. i.e. only in first time the page load. You can bind dropdown in !IspostBack condition in page_load event
vinay0801 25-Jan-12 7:01am    
no actually in the database in subject column one data has the subject Entertainment but on selecting entertainment in main page its not displaying that data.
If i change the query where subject='" + mainsubject.selecteditem.text.trim() + "'
to subject='entertainment' then its going to display that data.but i dont want that way.
That's Aragon 25-Jan-12 7:08am    
Try to debug it and check the quryAddBlog variable value. It should generate as expected. I think the dropdown value is not getting properly in the select statement.
manognya kota 25-Jan-12 7:36am    
In which event are you writing your code to get the data from database?

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