dropdownlist's selected index value is not printing the selected value

Here iS my code

.Aspx Page

<asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >

 

</asp:DropDownList>

<asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" />

my aspx.cs

protected void Page_Load(object sender, EventArgs e)

{

fillddlkeyword();

}

protected void Page_Init(object sender, EventArgs e)

{

}

private void fillddlkeyword()

{

string StrSql = "Select distinct(formName)as formName from tbl_form";

oDB.RunDBQuery(StrSql, out oRS);

DataTable dt = new DataTable();

dt.Columns.Add("Form");

if (oRS.HasRows)

{

while (oRS.Read())

{

DataRow dr = dt.NewRow();dr["Form"] = oRS["formName"].ToString();

dt.Rows.Add(dr);

}

oRS.Close();

}

oDB.Close();

// ddlkeyword.DataTextField = dt.Rows[0].ToString();

//ddlkeyword.DataTextField =

ddlkeyword.DataSource = dt;

ddlkeyword.DataBind();

//GridView1.DataSource = dt;

//GridView1.DataBind();

}

protected void Button1_Click(object sender, EventArgs e)

{

}

protected void ddlkeyword_SelectedIndexChanged(object sender, EventArgs e)

{

fillddlkeyword();

Response.Write(ddlkeyword.SelectedItem.ToString());

}

Any Clue???

Thanks  in Advance!!!

0
krishnada25
1/13/2009 9:52:17 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
1011 Views

Similar Articles

[PageSpeed] 7

Can you call the

Response.Write(ddlkeyword.SelectedItem.ToString());

before you call fillddlkeyword();


"Sector clear"
0
tehremo
1/13/2009 11:38:42 PM

1- You need to put IsPostBack Check on your page_load Event

 

protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack)

{

fillddlkeyword();

}

}

 

 2- No Need to re-fill combo box on selectedindex change event

 

protected void ddlkeyword_SelectedIndexChanged(object sender, EventArgs e)

{

fillddlkeyword();

Response.Write(ddlkeyword.SelectedItem.ToString());

}

3- Make sure that you have set autopostback=true on dropdown list property


Zeeshan Umar

~ Please Mark as Answer if it solves your query ~
0
sirdneo
1/14/2009 7:24:53 AM

Thanks Alot It's solved.

0
krishnada25
1/14/2009 3:51:19 PM

You are welcome


Zeeshan Umar

~ Please Mark as Answer if it solves your query ~
0
sirdneo
1/15/2009 9:25:23 AM
Reply:

Similar Artilces:

Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item
In the vb.net codebehind, I need to extract something from the Text (displayed) value of dropdownlist's selected item and I have  the SelectedValuand and SelectedItem in hand. How can I do this?  FindControl? Item? row?   Thanks. Well, its easier than you might think. SelectedItem has a "text" property. Thats the selected text right there :)  If you need the Text of the selection, then you have to use the SelectedItem.Text property.  If you want the value (not the displayed text) the you can directly use the SelectedValue. dim sText as String = dropdown...

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

dropdownlist
i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manual...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Get RadioButtonList's selected value and index using Javascript
Hey,I cannot figure out the way to get the selected value of a radiobuttonlist. Here is the code: function PageIsFilleOut(i_name, limitt){        var temp = limitt - 1;        var check_text_area = new Boolean(false);        var index=1;                for (index = 1; index <= temp; index++)        {            var name_t =...

Getting the selected value from an embedded DropDownList in GridView's ItemTemplate when Updating
Hi all, I wrote about this problem but none could help me so I'm posting it again with hope someone help me to solve this problem.OK. I have a GridView(ProductsGridView) bound to an ObjectDataSourceObject. One of the Columns is with DDL, which takes the CategoryID from the Product. The problem comes when I start to Edit the Row, it goes to edit mode, I change the Category for example, and then when I hit the Update button the value from the DDL is not Updated. It still has the value which it has at first. How can I get the Updated value and give it to my Business Object(Product)? Th...

How to change the dropdownlist's value from database on selection of 1 st dropdownlist
Hi Friends, I have 2 dropdownlist. 1 for country and 1 for state. When i will select any coutary according to that all state related to that countary shoud change in dropdownlist. I have to fatch both dropdownlist's value from sqlserver database. And i also don't know how to make relationship to get all value in aspx page. so please also tell me what should i made in database means primary foreign key concept. I will be very thankful if you can send me code for that.    There will be 2 tables in the database, Country with country_id as primary key. Another table Stat...

DropDownList Selected value to set gridview selected Index and page
I have a dropdownlist and a gridview that is bound to the same objectdatasource. In the gridview I am allowing paging.  When user select an item in the dropdownlist list I want to position the gridview selected value to that page and that record. Is there an easy way to do this. I tried this code Protected Sub GrdMyIssues_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdMyIssues.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'find the position data selected in the If e.Row.Cells(1).Text = Me.ViewSt...

DROPDOWNLIST DOES NOT SELECT THE SELECTED VALUE
Hi all, i am using C# , asp.net vs2005. ajax 1.0 i am populating data programitically . when i select first value, dropdown control select the same. when i select second value ,dropdownlist select second value too But i does not continue  from third value onward . when i select third value, dropdownlist control select second value then after behavior reman the same no matter what i select dropdownlist control select second value ONLY.<asp:DropDownList id="Ddlzse" runat="server" Width="165px" Font-Bold="False" Fo...

how do I get the index value of the item selected in a dropdownlist?
Hello friends. This is driving me crazy. I have a table in access with the list of US states. That table has 3 column fields: idsStateID (the key field, which is a number) chrStateAbv (the abbreviation of the state, FL, AK, VA...) chrStateName(the name of the state, Florida, Arkansas,...) I have this code in a web form: getDataFromDB(conx, "select * from ltblState", da, ds, dt, "tblStates") 'retrieves the data from the database into a datatable (dt) and assigns "tblStates" to that table Me.droState.DataSource = dt 'th...

find out the selected value for a gridview based on it's element value
I have created a gridview with a column of checkboxes. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Regid" DataSourceID="sds1" > <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="LName" HeaderText="Last Name" SortExpression="LName" /> <asp:BoundField DataField="FName" HeaderText="First Name" SortExpression="FName" /> <asp:BoundField DataField="Dept" Hea...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

get value from <select> value & display value
hi all, i want these two bold values which are below,  underline value i can get but second bold value i m not avail to get please help.... <select><option value="ma">manoj</option> </select> regard khushak  P.S. if possible then Please with  java script other wise code behind New In .NET World See my post in this thread.  That should take care of you. Peter BrunoneMS MVP, ASP.NETFounder, EasyListBox.comDo the impossible, and go home early....

Web resources about - dropdownlist's selected index value is not printing the selected value - asp.net.getting-started

Resources last updated: 12/9/2015 8:13:43 AM