Click here to Skip to main content
15,668,691 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to bind resources to gridview. I searched a lot but no success.
I tried the following but it doesn't show gridview at all:-

What I have tried:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            <asp:TemplateField HeaderText="MyHeader">
                        <asp:Label ID="Label1" runat="server"
                            Text="<%$ Resources:Resource, Header1 %>"></asp:Label>
                    <asp:TextBox ID="TextBox1" runat="server" Text="<%$Resources:Resource, Header1 %>"></asp:TextBox>
                    <asp:Label ID="Label1" runat="server" Text="<%$Resources:Resource, Header1 %>"></asp:Label>
Updated 23-Jan-22 23:34pm
F-ES Sitecore 1-May-17 10:11am    
You need to give the gridview a datasource and call the Bind method.

You need to bind data to GridView Control with below code -

GridView1.DataSource = "YOUR_DATASOURCE";

Also, you have set
for your gridview control so if you need to wrap any logic/functionality around your code before binding you need to implement it like -

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    //this will iterate with all rows available in gridview
    if (e.Row.RowType == DataControlRowType.DataRow)
        //put your control name here to get and then check for your value
        TextBox textBoxControl = e.Row.FindControl("TextBox1") as TextBox;
        textBoxControl.Text = "YOUR_DB_VALUE_FOR_TEXTBOX_TO_ASSIGN"; // assign values from your datasource to textbox control
Share this answer
you can get from your database like: male, female
bind with datasource

<%# GetLocalResourceObject(Eval("sex"))%>
Share this answer
Richard Deeming 24-Jan-22 6:31am    
Not relevant to the question that was asked.

If you're going to post a new solution to an old question, make sure you have read and understood the question, and that your solution adds something new to the discussion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900