Please visit my new Web Site https://coderstechzone.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:
Hope now you can get gridview row index in edit mode to enable or disable or soh or hide controls conditionaly.
1 comments:
IT WAS REALY GOOD ONE SIR..I LIKED IT..THANK U ..GOD BLESS U
I WOULD BE DELIGHTED TO HEAR FROM YOU