Hi,
I´m new to Asp.Net and C#, so I need some help
I have an aspx page on which I have 1 RadioButtonList, and 3 DropDownLists
I populate the DropDownLists and RadioButtonList from database with DataBind() in the Page_Load
then I need to select from the 4 forms and on a click of a button to get the selected values and text for further use.
How do I do this? Which options to set in the forms ( like AutoPostBack, AppendDataBoundItems, OnSelectedIndexChange ) and so on.
So far I just can get it work with getting the items from the RadioButtonList and the last DropDownList
any help will be more than wellcomed
thanks
Probi
Probi ForumiPosted May 21, 2008, 6:22 AM
Thanks a lot
this works now
thanks for everything
Probi
KiranPosted May 20, 2008, 2:04 PM
The only difference I see here is you are not setting values for the items in the first 2 ddls.
If you don't have specific values to set, set it the same as text like
Dropdownlist1.items[k].Value = items1[k];
See if this works.
Probi ForumiPosted May 20, 2008, 12:25 PM
the code for the first 2 lists:
OracleDataAdapter ad1 = new OracleDataAdapter(cmd1, connection);DataSet ds1 = new DataSet();
ad1.Fill(ds1);
DataView dw1 = new DataView(ds1.Tables[0]);
DropDownList1.DataSource = dw1;
DropDownList1.DataBind();
for (int k = 0; k < DropDownList1.Items.Count; k++){DropDownList1.Items[k].Text = items1[k];
} OracleDataAdapter ad2 = new OracleDataAdapter(cmd2, connection); DataSet ds2 = new DataSet();ad2.Fill(ds2);
DataView dw2 = new DataView(ds2.Tables[0]);DropDownList2.DataSource = dw2;
DropDownList2.DataBind();
for (int l =0; l < DropDownList2.Items.Count; l++){DropDownList2.Items[l].Text = items2[l];
}hope this makes it more clear... I honestly don´t know what I´m doing wrong
Thanks for all the help
Probi
KiranPosted May 20, 2008, 11:50 AM
Probi,
Are you binding the first two dropdowns same way? I appreicate if you post the databinding code for the first two.
Do you have static items in the dropdown list that you would like the database records to append to, like "Please select.."? If not, the appenddatabounditems doesn't make sense to me. Also here, since you are using the click event to retrieve the dropdownlist values, you don't need to set Autopostback = true, you can leave it as false just like you have now.
Probi ForumiPosted May 20, 2008, 9:46 AM
The code :
the dropdownlists in aspx page
<
asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" AutoPostBack="false" OnSelectedIndexChanged="ddl1_change" Font-Bold="false" Font-Names="verdana" Font-Size="small" ForeColor="darkviolet" >asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AppendDataBoundItems="true" AutoPostBack="false" OnSelectedIndexChanged="ddl2_change" Font-Bold="false" Font-Names="verdana" Font-Size="small" ForeColor="darkviolet" >asp:DropDownList><asp:DropDownList ID="DropDownList3" runat="server" AppendDataBoundItems="true" AutoPostBack="false" OnSelectedIndexChanged="ddl3_change" Font-Bold="false" Font-Names="verdana" Font-Size="small" ForeColor="darkviolet" >asp:DropDownList>
I populate the dropdownlists with this code
OracleDataAdapter ad3 = new OracleDataAdapter(cmd3, connection1); DataSet ds3 = new DataSet();ad3.Fill(ds3);
DataView dw3 = new DataView(ds3.Tables[0]);DropDownList3.DataSource = dw3;
DropDownList3.DataBind();
for (int n = 0; n < DropDownList3.Items.Count; n++){DropDownList3.Items[n].Text = artifacts[n] ;
DropDownList3.Items[n].Value = codes[n];}
and acces in the button - click event like this
protected void create( object sender, EventArgs e)
{ string ddl1_text, ddl2_text, dd3_val, ddl3_text;
if ( Page.IsPostBack)
{ ddl1_text = DropDownList1.SelectedItem.Text;
ddl2_text= DropDownList2.SelectedItem.Text;
ddl3_val = DropDownList3.SelectedItem.Value;ddl3_name = DropDownList3.SelectedItem.Text;
....
}
}
now this gets some values, but just the first ones in the list 1 and list 2 and the selected one in list 3
any ideas how to solve this?
thanks for the help
Probi
KiranPosted May 20, 2008, 9:15 AM
When you set "AutoPostBack" = true, the selected values should be available on a 'change' event, otherwise you don't get the values until the 'click' event occurs, i.e, until you click a button or a link on a form.
Can you post your code (definitions of your dropdownlists, how you are accessing the values)? that might help me see if there is any problem.
Probi ForumiPosted May 20, 2008, 6:09 AM
Hi,
first thanks for the responce.
I´m working in C# but I tried to do what u adviced, but it is not working still
when I put AutoPostBack =true for every DropDownList I dont see the selected values in the lists and in the end the only value I get is the one of the last DropDownList
what am I doing wrong?
Thanks
Probi
KiranPosted May 19, 2008, 4:31 PM
For the radiobutton list, selected item can be retrieved as
RadioButtonList1.SelectedItem.Text
For the dropdowns, set "AutoPostBack = true" and specify a method that handles the selectedindexchanged event like
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">
Now, in the method, access the selected item by selecteditem.value
Sub Selection_Change(sender As Object, e As EventArgs)
' do the processing
' based on the value selected by the user from the
' DropDownList control.
End Sub
The selected value of the dropdownlist can be obtained in three ways.
ddlTest.SelectedItem.Value
ddlTest.SelectedItem.Text
ddlTest.SelectedValue
HTH.