Wednesday, February 3, 2010

Enable disable show hide controls in grdview edit mode RowEditing or PreRender method




Please visit my new Web Site WWW.Codedisplay.com



In many asp.net (C# VB.Net) forum i found that developers ask how to enable or disable or show or hide asp.net server side controls like textbox,label,checkbox,checkboxlist,radiobutton,radiobuttonlist & dropdownlist or combo box in gridview edit mode. Everyone tries to find those controls within RowEditing event handler but they didn't get the control by using findcontrol method and editindex number. The findcontrol method will return null since in RowEditing eventhandler we didn't reference the controls in runtime data editing mode. But there is an alternative so that we can reference the above controls within gridview edit mode is PreRender method. In PreRender method we can access each edit template controls so that we can easily hide or show or enable or disable those controls.

If you want to read "DropDownList RadioButtonList CheckBox CheckBoxList in GridView Edit Mode in Asp.Net" then click here.

I have added a method named GridView1_PreRender which is a sequence of above article. So you can read first the above article & then continue with this one.

My sugession is in RowEditing method you didn't get control reference use prerender method in the following way:
protected void GridView1_PreRender(object sender, EventArgs e)
    {
        if (this.GridView1.EditIndex != -1)
        {
            DropDownList cboSize =(DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("cboSize");
            if (cboSize != null)
            {
                // You can apply condition here
                cboSize.Enabled = false;
            }

        }
    }
The output:
Show hide enable disable controls in gridview edit mode

Hope now you can get gridview row index in edit mode to enable or disable or soh or hide controls conditionaly.

1 comments:

MANJUNATH B Y said...

IT WAS REALY GOOD ONE SIR..I LIKED IT..THANK U ..GOD BLESS U

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash