User-893317190 posted
Hi JagjitSingh ,
You could get the cell through headerText property of the column, but the type of the cell should be DataControlFieldCell and you should get the cell through for each.
Below is my code.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:TemplateField HeaderText="myOwnText">
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address] FROM [Customers]"></asp:SqlDataSource>
Code behind.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
TableCellCollection tableCellCollection = e.Row.Cells;
foreach (DataControlFieldCell item in tableCellCollection)
{
if (item.ContainingField.HeaderText == "myOwnText")
{
item.Text = "hello";
}
if(item.ContainingField.HeaderText== "CustomerID")
{
item.Text = item.Text + "myEdit";
}
}
}
}
The result.

Best regards,
Ackerly Xu