.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Finding an ID of a DropDownList in a page

Posted By:Dhiraj Ranka       Posted Date: July 31, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

This article describes how to find the ID of the DropDownList in a page.

This article describes that how we can find the DropDownList id in a page. Consider that we a page, grid view and a drop down list. We have to put following javascript code in our page.

Now considering that SQL Data source is SqlDataSource1 which is bind with GridView.


And our code behind would look like this
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
    if (e.Row.RowType == DataControlRowType.Header) {
        //adding an attribute for onclick event on the drop down list in the header
        //and passing the ClientID of the Select All drop down list 
       ((DropDownList)e.Row.FindControl("ddlSelectAll")).Attributes.Add("onclick", "javascript:showDropDownID('" + ((DropDownList)e.Row.FindControl("ddlSelectAll")).ClientID + "')");
Finally run it.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend