Geeks With Blogs

@azamsharp
  • azamsharp The WWDC app says that there are new videos but there is nothing under videos!!! about 406 days ago
  • azamsharp Can I post my opinion on iOS 7 Beta or is it under NDA or something? about 406 days ago
  • azamsharp iOS 7 BETA installed successfully! about 406 days ago
  • azamsharp iOS 7 BETA installed! Now restoring! I am on NET10 which uses AT&T network. Hopefully 3G will still work! Lets c.. about 406 days ago
  • azamsharp The missing of button borders in Xcode 5 makes it hard to determine the clickable area. about 406 days ago
  • azamsharp I might wait for iOS to be released before I can put it on my device! Don't want a bricked or unstable device! about 406 days ago
  • azamsharp Android has many features that no one uses, number of versions that no one upgrades to and thousands of apps that no one pays for. about 406 days ago
  • azamsharp Maybe it is just me but the new iOS 7 UI looks like Windows Phone 8 UI! #maybeIamCrazy about 406 days ago
  • azamsharp Anyone using H20 network upgraded to iOS 7 BETA Keep me updated if you face any problems. about 406 days ago
  • azamsharp @merowing_ You already downloaded it! I cannot even load the developer's website! :( about 407 days ago

AzamSharp Some day I will know everything. I hope that day never comes.

Sometimes you have two DropDownLists inside the GridView Item Tempalte Field. This scenario is encountered when the DropDownList have a parent-child relationship. So, you want to select some item from the parent and fill the child list based on the parent selection. If GridView control was not involved in this triangle then it would have been pretty simple but GridView makes it little different.

The first thing that you need to do is to put the AutoPostBack on the parent DropDownList to true. Now, you can implement the SelectedIndex_Changed event of the DropDownList (Parent).

 

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)

{

string foundID = String.Empty;

GridViewRow row = (GridViewRow)((sender) as Control).NamingContainer;

// get the value from the first dropdownlist

DropDownList ddlFirst = ((sender) as DropDownList);

int ddlFirstSelectedValue = Convert.ToInt32(ddlFirst.SelectedValue);

string firstDropDownListID = ddlFirst.UniqueID;

// and now here is how

DropDownList ddlSecond = row.FindControl("ddl2") as DropDownList;

// now from here you can do whatever you want!

}

 

Nothing too fancy about the above code. I just used the NamingContainer to find the selected row in which the user has changed the DropDownList (Parent) selection. Then I get the value from the parent DropDownList and populate the child DropDownList by simply referering it by its ID. 

This is it!  

Posted on Friday, September 15, 2006 2:02 PM | Back to top


Comments on this post: Multiple DropDownLists Inside the GridView Item Template Field

# re: Multiple DropDownLists Inside the GridView Item Template Field
Requesting Gravatar...
Hi

I have used this quite some time before. Very useful in live projects
Left by vikram on Sep 15, 2006 10:47 PM

# re: Multiple DropDownLists Inside the GridView Item Template Field
Requesting Gravatar...
Hi
If we want to avoid postback but needs to have same functionality; How to do this?
We tried with client callbacks but doesn't get the result.

Thanks
Mandar
Left by Extension on Sep 21, 2006 11:17 PM

# re: Multiple DropDownLists Inside the GridView Item Template Field
Requesting Gravatar...
Multiple controls with the same ID 'DropDownList1' were found. FindControl requires that controls have unique IDs.
It gives the above when i use ur code plz adivce
Left by rakesh on Oct 06, 2007 12:29 AM

Your comment:
 (will show your gravatar)
 


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net | Join free