Reputation: 838
I have a problem with getting value of template field; Gridview is in ContentPlaceHolder1;
I'm trying to get value in GridView1_RowCreated event
int RowIndex = GridView1.Rows.Count - 1;
GridView1.Rows[RowIndex].Cells[0].Text = " " + AltKatLinkler;
But this code returns me null or empty.
There is my column, column index is 0. Note: I fill GridView by using SqlDataSource. There is no problem i can see row content in browser but i cant access from codebehind.
<asp:templatefield headertext="Haberler" sortexpression="KategoriID" xmlns:asp="#unknown">
<ItemTemplate>
< a href='<%# "KategoriGoster.aspx?KategoriID=" + Eval("KategoriID")%>'>
<%# Eval("KategoriAd")%>
<%# Eval("Açıklama")%>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 3
Views: 11420
Reputation: 8474
see another way to do it
<asp:templatefield headertext="Haberler" sortexpression="KategoriID" xmlns:asp="#unknown">
<ItemTemplate>
< a href='<%# "KategoriGoster.aspx?KategoriID=" + Eval("KategoriID")%>'>
<asp:Label ID="lbKategori" runat="server" Text='<%# Eval("KategoriAd").ToString() %>'></asp:Label>
<asp:Label ID="lbAçıklama" runat="server" Text='<%# Eval("Açıklama").ToString() %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Codebehind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var lbKategori = e.Row.FindControl("lbKategori") as Label;
var lbAçıklama = e.Row.FindControl("lbAçıklama") as Label;
}
}
Upvotes: 2