Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hi guys,


I'm very confused, how to write OnSelectedIndexChanged Event of a dropdownlist.

SCENARIO:

---------------------------------------------------------------------------
|Repeater 1                                                                |
---------------------------------------------------------------------------
| ------------------------------------------------------------------------ |
| |Repeater 2                                                             ||
| |-----------------------------------------------------------------------||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [1]                 ||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [2]                 ||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [3]                 ||
| |-----------------------------------------------------------------------||
| -------------------------------------------------------------------------|
----------------------------------------------------------------------------


I have populated d dropdownlist which is in d WebUserControl,
but, now the problem is,
How to write its "OnSelectedIndexChanged" event.
So that, If i select any value in d dropdownlist, its text should also appear in
the textbox of that WebUserControl.

Plzzzz guys help me.


thanks
Posted
Updated 23-Apr-14 0:07am
v3
Comments
nandakishoreroyal 23-Apr-14 6:09am    
Paste the code, then we can know where you have struck.

You should update the code what you have tried, dont paste these type of questions.
Sunasara Imdadhusen 23-Apr-14 6:31am    
It would be great if you can provide code snippet!!
[no name] 23-Apr-14 6:31am    
please show the code..

your requirement is not clear , i think you want OnSelectedIndexChanged event of the dropdown inside the Repeater

in the above case , add your dropdown outside the repeater and create that event (just click) after that cut that dropdown from there and paste inside Itemtemplate of the Repeater.
 
Share this answer
 
v2
Comments
abdul subhan mohammed 23-Apr-14 10:16am    
Dear, its in web user control...
you can make the OnSelectedIndexChanged event in your web user control.
In the web user control you can make a
C#
public event Action<string>OnSelectedIndexChangedDropDownListEvent;

This event can be subscribed to by the pages that uses your web user control.
in the web user control in the method for the OnSelectedIndexChanged you write:

C#
if (OnSelectedIndexChangedDropDownListEvent!=null)
    OnSelectedIndexChangedDropDownListEvent(dropdownListNameHere.SelectedValue);

So the inner event is posted to the outside world via the OnSelectedIndexChangedDropDownListEvent.
 
Share this answer
 
v2
Comments
abdul subhan mohammed 23-Apr-14 11:47am    
thnx digimanus.... its working... thnx again :)
Dipak Y Salve 24-Apr-14 2:36am    
Abdul, can you share your code please?
C#
protected void rptrSection1_Bound(object sender, RepeaterItemEventArgs e)
{
var ctl = e.Item.FindControl("ddlS1") as SDropDownList;
ctl.SelectedIndexChanged += new EventHandler(ddlS1_SelectedIndexChanged);
}

[code]....
 
Share this answer
 
I just did this event as public under Web User Control code behind, i.e., WUC.cs:

public void ddlchemicals_SelectedIndexChanged(object sender, EventArgs e)
        {
            int recid = Convert.ToInt32(ddlchemicals.SelectedValue);
            DataTable dt = new DataTable();
            dt = bl.GetSelectedSubChemicals(recid);
            txtdescription.Text = dt.Rows[0]["Descriptions"].ToString();
            txtunit.Text = dt.Rows[0]["Units"].ToString();
            dt = null;
        }


that's it,

Thnx everyone
 
Share this answer
 
v2

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