如何从Asp.Net表中绑定两个下拉列表 [英] How to Bind Two dropdown List from Asp.Net Table

查看:98
本文介绍了如何从Asp.Net表中绑定两个下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Asp.Net表,在这个表中有多个下拉列表和税箱,所以如何绑定相应的dropdownList。



我想---------当我选择First DropdownList然后Second Dropdown Will Autofill for relative Data它有多个Row Means Taht Dynamic Row Genrate。



我的表格是....

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....

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







告诉我关于secong下拉列表的代码位置,The Row是不能修复多个



c #Code ---




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

c# Code---

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);
                       }      
}          
}

推荐答案

将SelectedIndexChanged事件添加到第一个下拉列表并填写第二个下拉列表dropdown。(根据dbrenth)
Add SelectedIndexChanged event to the first dropdown and fill your second dropdown.(as per dbrenth)


请参阅下面有关如何实施Cascade Dropdownlist的链接



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



基于populate-dropdown-selection-other [ ^ ]
Refer below links on how to implement Cascade Dropdownlist

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

populate-dropdown-based-selection-other[^]


你有两个解决方案。我没有时间给你样品。



#1在代码隐藏中处理SelectedIndexChanged事件。填充代码隐藏中的第二个下拉列表并回发。如果你使用AJAX(asp:ScriptManager和asp:UpdatePanel),你应该能够让它看起来好像从来没有回发过。如果你不得不回到数据库,那么这个更好。



#2创建一个javascript事件处理程序来执行相同的操作。



祝你好运
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


这篇关于如何从Asp.Net表中绑定两个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆