Get the value of TemplateFields in Gridview

I have a problem getting the value of a template field; Gridview is in ContentPlaceHolder1;

I am trying to get the value in the GridView1_RowCreated event

int RowIndex = GridView1.Rows.Count - 1;
GridView1.Rows[RowIndex].Cells[0].Text = " " + AltKatLinkler;

But this code returns me empty or empty.

There is my column, the column index is 0. Note. I populate a GridView using SqlDataSource. No problem, I can see the contents of the string in the browser, but I can’t access the codes.

<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>
+3
source share
1 answer

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;
        }
    }
+2
source

Source: https://habr.com/ru/post/1751350/


All Articles