Hi
I'm adding two dropdownlist in my webform by clicking a button. I fill
the first dropdown with some values from my DB and the other one when I
choose from the first dropdown. But since theese dropdownlists are
created by clicking a button they no longer exists on my webform. How
do I keep my dynamically created dropdown when using
OnSelectedIndex Changed? Can anyone help me solve this problem? Or is
there a better way of doing this?
Thanks
..christer
(here's some of my code)
aspx-page:
<asp:Button Runat="server" ID="btnAddGroup " Text="Add Main-/Subgroup"
/>
<asp:PlaceHolde r ID="phGroup" Runat="server" /><asp:PlaceHold er
ID="phSubGroup " Runat="server" />
code behinde (aspx.cs):
private void btnAddGroup_Cli ck(object sender, System.EventArg s e){
CreateDropDown( this.phGroup, "selMainGrp ");
}
private void CreateDropDown( PlaceHolder ph, string id){
DropDownList dd = new DropDownList();
FillMainGrpList Box(ph, dd, id);
}
private void FillMainGrpList Box(PlaceHolder ph, DropDownList dd, string
id){
DropDownList selMainGroup = dd;
string sqlProc = "GetMainGro up";
Data data = new Data();
resultDataSet = data.GetDataSet ByProcName(sqlP roc);
dd.Items.Add("C hoose");
//Fill control
foreach(DataTab le table in resultDataSet.T ables){
foreach(DataRow row in table.Rows){
foreach(DataCol umn col in table.Columns){
//Add maingroup to dropdownlist
selMainGroup.It ems.Add(row[col].ToString());
}
}
}
//Add control
string sAttributes;
sAttributes = "<b>Main Group</b>";
ph.Controls.Add (new LiteralControl( sAttributes));
selMainGroup.ID = id;
selMainGroup.Au toPostBack = true;
selMainGroup.Se lectedIndexChan ged +=new
EventHandler(se lMainGroup_Sele ctedIndexChange d);
ph.Controls.Add (selMainGroup);
//Add Subgroup dropdown
DropDownList ddSub = new DropDownList();
sAttributes = "<b>Sub group</b>";
ddSub.ID = "selSubGrp" ;
ddSub.Items.Add ("Choose");
phSubGroup.Cont rols.Add(new LiteralControl( sAttributes));
phSubGroup.Cont rols.Add(ddSub) ;
}
private void selMainGroup_Se lectedIndexChan ged(object sender,
System.EventArg s e){
string mainGroupValue = this.selMainGrp .SelectedValue;
if(mainGroupVal ue != "Choose"){
//Reset subgroup dropdown
SetDefaultListB oxValue(selSubG rp);
//Add values in subgroup
FillSubGrpListB ox(mainGroupVal ue);
}
}
private void FillSubGrpListB ox(string mainGroupValue) {
string sqlProc = "GetSubGrou p";
string[,] paramArr = {{"@MainGroup", mainGroupValue} };
Data data = new Data();
resultDataSet = data.GetDataSet ByProcName(sqlP roc, paramArr);
foreach(DataTab le table in resultDataSet.T ables){
foreach(DataRow row in table.Rows){
foreach(DataCol umn col in table.Columns){
selSubGrp.Items .Add(row[col].ToString());
}
}
}
} 8 3393
Instead of creating the ddls dynamically, put them on the .aspx form in a
normal way and, in run time, control their visibility and databinding
properties.
Eliyahu
<ut*******@gmai l.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com... Hi
I'm adding two dropdownlist in my webform by clicking a button. I fill the first dropdown with some values from my DB and the other one when I choose from the first dropdown. But since theese dropdownlists are created by clicking a button they no longer exists on my webform. How do I keep my dynamically created dropdown when using OnSelectedIndex Changed? Can anyone help me solve this problem? Or is there a better way of doing this?
Thanks .christer
(here's some of my code) aspx-page: <asp:Button Runat="server" ID="btnAddGroup " Text="Add Main-/Subgroup" /> <asp:PlaceHolde r ID="phGroup" Runat="server" /><asp:PlaceHold er ID="phSubGroup " Runat="server" />
code behinde (aspx.cs): private void btnAddGroup_Cli ck(object sender, System.EventArg s e){ CreateDropDown( this.phGroup, "selMainGrp "); }
private void CreateDropDown( PlaceHolder ph, string id){ DropDownList dd = new DropDownList(); FillMainGrpList Box(ph, dd, id); }
private void FillMainGrpList Box(PlaceHolder ph, DropDownList dd, string id){ DropDownList selMainGroup = dd; string sqlProc = "GetMainGro up";
Data data = new Data();
resultDataSet = data.GetDataSet ByProcName(sqlP roc);
dd.Items.Add("C hoose");
//Fill control foreach(DataTab le table in resultDataSet.T ables){ foreach(DataRow row in table.Rows){ foreach(DataCol umn col in table.Columns){ //Add maingroup to dropdownlist selMainGroup.It ems.Add(row[col].ToString()); } } }
//Add control string sAttributes; sAttributes = "<b>Main Group</b>"; ph.Controls.Add (new LiteralControl( sAttributes)); selMainGroup.ID = id; selMainGroup.Au toPostBack = true; selMainGroup.Se lectedIndexChan ged +=new EventHandler(se lMainGroup_Sele ctedIndexChange d); ph.Controls.Add (selMainGroup);
//Add Subgroup dropdown DropDownList ddSub = new DropDownList(); sAttributes = "<b>Sub group</b>"; ddSub.ID = "selSubGrp" ; ddSub.Items.Add ("Choose"); phSubGroup.Cont rols.Add(new LiteralControl( sAttributes)); phSubGroup.Cont rols.Add(ddSub) ; }
private void selMainGroup_Se lectedIndexChan ged(object sender, System.EventArg s e){ string mainGroupValue = this.selMainGrp .SelectedValue; if(mainGroupVal ue != "Choose"){ //Reset subgroup dropdown SetDefaultListB oxValue(selSubG rp);
//Add values in subgroup FillSubGrpListB ox(mainGroupVal ue); } }
private void FillSubGrpListB ox(string mainGroupValue) { string sqlProc = "GetSubGrou p";
string[,] paramArr = {{"@MainGroup", mainGroupValue} };
Data data = new Data(); resultDataSet = data.GetDataSet ByProcName(sqlP roc, paramArr);
foreach(DataTab le table in resultDataSet.T ables){ foreach(DataRow row in table.Rows){ foreach(DataCol umn col in table.Columns){ selSubGrp.Items .Add(row[col].ToString()); } } } }
What I want to do is click on my "Add"-button and create two dropdowns
- the first I fill with values from my DB. Then I select a value from
the first drop down and fill the other drop down (with another
roundtrip to my DB collecting the new values for the second dropdown).
When that's done I want to click my "Add Selection"-button and add the
selection to my webform (values from both dropdowns). After that I
would like to add another dropdown make my selection and and add it to
my webform, and so on.
When I've made all my selections I would like to press a "Save"-button
and save all the selected values to my DB.
Thus, I do not know in advance how many selections I would like to make
and thats why I wanna create theese controls at run time.
Hope this clarified a bit
..christer
Do you mean that first "Add" click produces 2 ddls, then another "Add"
produces another 2 ddls and you will have 4 ddls on the form? And 6 ddls
after the third click?
Can't you use the same pair of ddls for every "Add" click?
Eliyahu
<ut*******@gmai l.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . What I want to do is click on my "Add"-button and create two dropdowns - the first I fill with values from my DB. Then I select a value from the first drop down and fill the other drop down (with another roundtrip to my DB collecting the new values for the second dropdown). When that's done I want to click my "Add Selection"-button and add the selection to my webform (values from both dropdowns). After that I would like to add another dropdown make my selection and and add it to my webform, and so on.
When I've made all my selections I would like to press a "Save"-button and save all the selected values to my DB.
Thus, I do not know in advance how many selections I would like to make and thats why I wanna create theese controls at run time.
Hope this clarified a bit .christer
Ok. But how do I preserve (and view) the value when I click my "Add
selection"-button?
If I use a <asp:placeholde r ../> for instance and try to place my drop
down values in that place when clicking "Add selection" the page
reloads and selection (value) is gone.
..christer
If you have 2 static ddls, what stops you from getting their selected values
on server side in the "Add selection" onclick event handler?
Eliyahu
<ut*******@gmai l.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com... Ok. But how do I preserve (and view) the value when I click my "Add selection"-button?
If I use a <asp:placeholde r ../> for instance and try to place my drop down values in that place when clicking "Add selection" the page reloads and selection (value) is gone.
.christer
I am lousy at explaining I think. And my english ain't what it should
be.
I want to preserve/add values in a placeholder when I make my
selection. I can do this with my first dd selection like this.
- Make my selection in my drop down
- Add selection to a placeholder by clicking "btnAddSale s"
aspx:
<label for="selSalesAc count">Sales Account:</label>
<asp:DropDownLi st Runat="server" ID="selSalesAcc ount"
AutoPostBack="T rue" />
<asp:Button Runat="server" ID="btnAddSales " />
<asp:PlaceHolde r Runat="server" ID="phSales" />
code behind:
private void btnAddSales_Cli ck(object sender, EventArgs e){
string val = this.selSalesAc count.SelectedV alue;
TextBox tb = new TextBox();
tb.ID = val;
this.phSales.Co ntrols.Add(tb);
tb.Text = val;
tb.AutoPostBack = true;
}
So now I have my first drop down selection in my placeholder. Now I
want to make another selection from my dropdown and add its value to my
placeholder (making it two values) - but when I choose a new item in
the drop down values preserved in my placeholder is gone.
How do I keep thees selected values when I do another runtrip to the
server?
(this is a simplyfied example of what I want to do, but if I can get
help with this I should be able to sort the rest out myself)
..christer
A placeholder is not good for you. First of all, choose a class you want to
use to store the selection. It could be an array, ArrayList, SortedList,
DataTable. Secondly, decide on how to make it persistent between the
postbacks. You can put it in a session variable or in the ViewState. Then
finally chose a web control that will render your selection on the page.
Typically it would be a datagrid, a datalist or a repeater. And finally bind
your control to your storage object on every postback.
Eliyahu
<ut*******@gmai l.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. . I am lousy at explaining I think. And my english ain't what it should be.
I want to preserve/add values in a placeholder when I make my selection. I can do this with my first dd selection like this. - Make my selection in my drop down - Add selection to a placeholder by clicking "btnAddSale s"
aspx: <label for="selSalesAc count">Sales Account:</label> <asp:DropDownLi st Runat="server" ID="selSalesAcc ount" AutoPostBack="T rue" /> <asp:Button Runat="server" ID="btnAddSales " /> <asp:PlaceHolde r Runat="server" ID="phSales" />
code behind: private void btnAddSales_Cli ck(object sender, EventArgs e){ string val = this.selSalesAc count.SelectedV alue; TextBox tb = new TextBox(); tb.ID = val; this.phSales.Co ntrols.Add(tb); tb.Text = val; tb.AutoPostBack = true; }
So now I have my first drop down selection in my placeholder. Now I want to make another selection from my dropdown and add its value to my placeholder (making it two values) - but when I choose a new item in the drop down values preserved in my placeholder is gone.
How do I keep thees selected values when I do another runtrip to the server?
(this is a simplyfied example of what I want to do, but if I can get help with this I should be able to sort the rest out myself)
.christer
Ok thanks!
I'll try that.
..christer This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ashish Sharma |
last post by:
I have a drop down list inside a data list on a form like this :
<asp:DataList ID="DataList1" runat="server" EnableViewState="False">
<ItemTemplate>
<asp:Label ID="lblname" Runat="server" text='<%#
DataBinder.Eval(Container.DataItem,"Name") %>'> </asp:Label>
<asp:DropDownList id="DropDownList1" runat="server" DataTextField="Name"
DataValueField="UID" OnSelectedIndexChanged="CallMySub"
AutoPostBack="True"></asp:DropDownList>...
|
by: Roshawn |
last post by:
Hi,
I have a DDL server control on my web form. I'm having difficulty trying to
fire the OnSelectedIndexChanged event. I've specified a procedure to handle
the event. Whenever I changed the selected index of the DDL server control,
the event doesn't fire at all. Below are the settings for the DDL server
control:
<asp:dropdownlist autopostback="true" id="Dlist" runat="server"
onselectedindexchanged="Selection_Changed" />
|
by: Nirmalkumar |
last post by:
How to attach an event to dynamically created control in VB.NET
I have dynamically created dropdown list in code behind (VB.NET). For this
control I want to attach an event for action ‘OnSelectedIndexChanged’.
What is the property to assigne an event to a dynamically created dropdownlist
|
by: Paul L |
last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
|
by: glenn |
last post by:
Hi folks,
I am trying to determine which item in a DropDownList Web control has been
selected.
I have posted an OnSelectedIndexChanged subroutine in my code with a
reference to the subroutine in my asp tag as shown here:
<asp:DropDownList
id="ddlTo"
runat="server"
| |
by: Santosh |
last post by:
Dear all ,
i am writting following code.
if(Page.IsPostBack==false)
{
try
{
BindSectionDropDownlist();
|
by: Iain |
last post by:
Hi All
I have 2 DropDownList boxes on a page.
The first (id= "Operation") is populated on PageLoad with the contents
of a database table.
The second id="WorkStations" will not be populated until the first has
been changed
The definitions are below.
|
by: swapnil1987 |
last post by:
hello friends i am trying to find solution for this problem if u know something then please tell
i am creating web application that runs on black berry.
here i need to create selection list which has three radio buttons in it.
but these are created dynamically. and i want to add event "onselectedindexchanged" for this list.
so how can i add this event when i am creating it dynamically.
|
by: user1980 |
last post by:
hello,
i am trying to create a request form using asp.net where when a user selects a checkbox, a dropdown should appear dynamically. I have seen few java-scripts in web, but I was wondering if I can achieve this without java-script.
I tried to make the control invisible(<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" Visible="False">) and in the onselectedindexchanged event, tried to make the invisible...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |