Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Have a Asp.Net Table and in this table more than one dropdownlist and taxboxes so how can I bind the corresponding dropdownList.

I wants---------when I select First DropdownList then Second Dropdown Will Autofill for relative Data it has multiple Row Means taht Dynamic Row Genrate.

My Table Is....
XML
<div class="field"><asp:Table ID="tblquotation" runat="server" CssClass="mGrid">
                               </asp:Table></div>



Tell me about The Code Location of secong dropdown, The Row is not Fix its more than one

c# Code---
C#
int count = Convert.ToInt32(ViewState["Product"].ToString());
                for (int i = 0; i <= count; i++)
                {
                    if (i == 0)
                    {
                        TableHeaderRow tr = new TableHeaderRow();
                        //TableRow tr = new TableRow();

                        TableHeaderCell tc1 = new TableHeaderCell();
                        tc1.Text = "S.No.";
                        tr.Cells.Add(tc1);



                        TableHeaderCell tc2 = new TableHeaderCell();

                        tc2.Text = "GroupName";
                        tr.Cells.Add(tc2);



                        TableHeaderCell tc3 = new TableHeaderCell();
                        tc3.Text = "Name";
                        tr.Cells.Add(tc3);
                        tblquotation.Controls.Add(tr);
                      }
                    else
                    {
                           TableRow tr = new TableRow();

                        TableCell tc1 = new TableCell();
                        tc1.Text = i.ToString();
                        tc1.HorizontalAlign = HorizontalAlign.Center;
                        tr.Cells.Add(tc1);


                        TableCell tc2 = new TableCell();
                        //TextBox txtbasic = new TextBox();
                        DropDownList txtbasic = new DropDownList();
                        SqlDataReader dr =   commonfunctions.ExecuteQueryReturnDataReader("sp_Group_Purchase");
                        if (dr.HasRows)
                        {
                            txtbasic.DataTextField = "GroupName";
                            txtbasic.DataValueField = "GId";
                            txtbasic.DataSource = dr;
                            txtbasic.DataBind();
                        }
                        txtbasic.Items.Insert(0, "<--Select-->");

                        txtbasic.ID = "txtbasic" + i.ToString();
                        txtbasic.AutoPostBack = true;
                        txtbasic.SelectedIndexChanged += txtbasic_SelectedIndexChanged;
                         
                        tc2.Controls.Add(txtbasic);
                        tc2.HorizontalAlign = HorizontalAlign.Center;
                        tr.Cells.Add(tc2);



                        TableCell tc3 = new TableCell();
                        //TextBox txtbasic = new TextBox();
                        DropDownList ddlName = new DropDownList();
                        SqlDataReader dr4 =  commonfunctions.ExecuteQueryReturnDataReader("sp_Itemname_Purchase");
                        if (dr4.HasRows)
                        {
                            ddlName.DataTextField = "ItemName";
                            ddlName.DataValueField = "ItemId";
                            ddlName.DataSource = dr4;
                            ddlName.DataBind();
                        }
                        ddlName.Items.Insert(0, "<--Select-->");

                        ddlName.ID = "ddlName" + i.ToString();

                       // txtbasic.Attributes.Add("onkeypress", "return isNumberKey(event);");
                        tc3.Controls.Add(ddlName);
                        tc3.HorizontalAlign = HorizontalAlign.Center;
                        tr.Cells.Add(tc3); 
                        tblquotation.Controls.Add(tr);
                       }      
}          
}
Posted
Updated 7-Mar-14 1:25am
v6
Comments
What is the exact issue?
Parmendra choudhary 7-Mar-14 1:18am    
I want to bind corresponding dropdown
That's fine. But where is the issue exactly?
Parmendra choudhary 7-Mar-14 7:00am    
please check My Code and please correct It, I want that when I select First Than second auto fill,

Add SelectedIndexChanged event to the first dropdown and fill your second dropdown.(as per dbrenth)
 
Share this answer
 
Comments
Parmendra choudhary 7-Mar-14 7:06am    
Yes you are right but the methods is not working properly
Sanket Saxena 7-Mar-14 7:45am    
Dear debug the code and let us know where the code breaks
gascomen 17-May-15 23:00pm    
I'm coding drop down list because error 'has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value' how to fix this error
Refer below links on how to implement Cascade Dropdownlist

Creating-Cascading-DropDownLists-in-ASP.Net[^]

populate-dropdown-based-selection-other[^]
 
Share this answer
 
You have two solutions. I don't have time to give you samples.

#1 Handle a SelectedIndexChanged event in your code-behind. Populate the second dropdown in your code-behind and post back. If you use AJAX (asp:ScriptManager and asp:UpdatePanel) you should be able to make it look like it never posted back at all. This one is better if you have to go back to the database.

#2 Create a javascript event handler that does the same thing.

Good Luck
 
Share this answer
 
Comments
Parmendra choudhary 6-Mar-14 23:41pm    
Thanks You

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