I need to change a specific cell in GridView
, but when I try to do this in RowDataBound
:
TextBox x = ((TextBox)e.Row.Cells[i].FindControl("ctl" + tx.PadLeft(2,'0')))
x.Enable = False;
or this way;
((TextBox)e.Row.Cells[i].FindControl("ctl")).Enable = false;
or this: e.Rows [i] .Cells [j] .Enable = false;
The whole column is affected, can someone help me change a cell
specified for a specific row / column.
My GridView Has the following HTML:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" Font-Size="XX-Small" ForeColor="#333333" Width="100%" HorizontalAlign="Center" PageSize="35" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#6E7265" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#BDC0C4" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" Wrap="True" BorderStyle="Double" BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" ForeColor="White" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
In html they can not dazzle the templteeField because it is created in the code behind as follows:
foreach (DataColumn col in x.Columns)
{
//Declare the bound field and allocate memory for the bound field.
TemplateField bfield = new TemplateField();
//Initalize the DataField value.
bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName);
//Initialize the HeaderText field value.
bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName);
//Add the newly created bound field to the GridView.
GridView1.Columns.Add(bfield);
}