Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,
In my gridview i have two dropdown ctrls name as DEPTNAME AND ROLE,
when i clicked Dept dropdown and selectd a dept then only the second dropdown role will be fired and shows that relating roles of dept,
if u know help me,,
Posted
Comments
Ankur\m/ 24-Jan-11 23:55pm    
There are many ways to do it. Do you need values from the database when you select a value from the first dropdownlist? If yes, you can use AJAX, if no - you can use JavaScript.

Check out AJAX CascadingDropDown[^].

If you do not need to get the values against the database, you may also use JavaScript to achieve the same.

Edit: Check how to use AJAX CascadingDropDown in GridView - http://www.google.co.in/#sclient=psy&num=10&hl=en&q=ajax+cascadingdropdown+inside+gridview&aq=f&aqi=&aql=&oq=&pbx=1&fp=ae1ee85e922f7961[^]


Hope this helps!
 
Share this answer
 
v2
Comments
Sandeep Mewara 25-Jan-11 0:16am    
Good answer, especially after the edit :)
Ankur\m/ 25-Jan-11 0:24am    
:DThanks!
U write the Role dropdownlist code in DEPTNAME_SelectedIndexChanged(object sender, EventArgs e) then Related roles will be displayed
 
Share this answer
 
Comments
honey4bee 24-Jan-11 23:50pm    
the ddldept in the gridveiw doesn't show any events,
sampath1750 25-Jan-11 0:01am    
1st u should write the code for ddldept by using<asp:listitem>---</asp:listitem> or Byusing Dataset then ddldept events will be displayed
sampath1750 25-Jan-11 0:14am    
I will give one example this is same as ajax cascading bt directly come
1 is Countryddl & 2nd Stateddl If we select country then related states only displayed.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetData();
}
}

void GetData()
{
try
{

string command = "select CountryId,CountryName From Country Order by CountryName";
da = new SqlDataAdapter(command, con);
ds = new DataSet();
da.Fill(ds, "Country");
CountryDropDownList.DataSource = ds;
CountryDropDownList.DataValueField = ds.Tables[0].Columns[0].ToString();
CountryDropDownList.DataTextField = ds.Tables[0].Columns[1].ToString();
CountryDropDownList.DataBind();
CountryDropDownList.Items.Insert(0, new ListItem("-- Select Category --", "0"));


}
catch (Exception ce)
{
MsgLabel.Text = ce.Message;
}
}

protected void CountryDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
StateDropDownList.Enabled = true;
{
try
{
string command = "select StateId,StateName From State where Countryid="+CountryDropDownList.SelectedValue+ "Order by StateName";
da = new SqlDataAdapter(command, con);
ds = new DataSet();
da.Fill(ds, "State");
StateDropDownList.DataSource = ds;
StateDropDownList.DataValueField = ds.Tables[0].Columns[0].ToString();
StateDropDownList.DataTextField = ds.Tables[0].Columns[1].ToString();
StateDropDownList.DataBind();
StateDropDownList.Items.Insert(0, new ListItem("-- Select Category --", "0"));

}
catch (Exception ce)
{
MsgLabel.Text = ce.Message;
}
}

}
honey4bee 25-Jan-11 0:12am    
my role vaues and dept values coming from database,
so i didn't use <asp:listitem>---</asp.listitem> in gridview

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