|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Disable CommandField for some rows of dataHi;
Based on a column value in each row of data, I only want the CommandField to be enabled if that column's value for that row is a specific value. For any other value I want the control to still be there, but disabled. How can I do that? Most likely you would have to use a TemplateField like I did with the
DetailsView: http://www.webswapp.com/codesamples/aspnet20/detailsview/default.aspx http://www.webswapp.com/codesamples/aspnet20/detailsview/default.aspx <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnFax" runat="server" Text="Send Fax" Enabled='<%# Eval("Fax").ToString().Trim<>String.Empty%>' /> </ItemTemplate> </asp:TemplateField> The CommandField can render more than one button (select, delete, Insert) none of which exposes the Enabled property. You might use the Visible property, e.g. e.Row.Cells[0].Controls[0].Visible= false, during the RowDataBound event: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.dataitem(VS.80).aspx Show quoteHide quote "David Thielen" wrote: > Hi; > > Based on a column value in each row of data, I only want the CommandField to > be enabled if that column's value for that row is a specific value. For any > other value I want the control to still be there, but disabled. > > How can I do that? > > -- > thanks - dave > david_at_windward_dot_net > http://www.windwardreports.com > Thanks for Phillip's good suggetion.
Hi Dave, If you need complex customization, the "RowDataBound" will be the one you need. Here is very simple use of it: I just disable the command cell according to the RowIndex, you can do it according to the DataBound value(get from e.Row.DataItem) protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if(e.Row.RowIndex == 3) e.Row.Cells[0].Enabled = false; } } Hope this also helps. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
How to get CommandField and ButtonField in the toolbox?
Binding TextBox Gridview custom sort - works but always sorts ascending DropDownlist problem Perform insert to gridview/table Creating Dynamic controls Datalist formatting questions Adding client side code to RadioButtonList control item??? Searching a list box using a text box Detecting if client-side validation javascript is registered? |
|||||||||||||||||||||||