1
I need to change a specific Cell in GridView
, but when I try to do it this way in RowDataBound
:
TextBox x = ((TextBox)e.Row.Cells[i].FindControl("ctl" + tx.PadLeft(2,'0')))
x.Enable = False;
or in this way;
((TextBox)e.Row.Cells[i].FindControl("ctl")).Enable = false;
or of: e. Rows[i]. Cells[j]. Enable = false;
The entire spine is affected, someone can help me change one cell
specifies 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 cannot dazzle templteeField because it is created in Behind code 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);
}
In which gridview event you are trying to change the cell value?
– anmaia
I’m trying to change in Rowdatabound
– user6018
Supplement your question with the HTML of
gridview
, I think it’ll be easier to understand.– anmaia