Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
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" 
        ShowHeaderWhenEmpty="True">
        <Columns>
            <asp:TemplateField HeaderText="MyHeader">
                <EditItemTemplate>
                <HeaderTemplate>
                        <asp:Label ID="Label1" runat="server"
                            Text="<%$ Resources:Resource, Header1 %>"></asp:Label>
                    </HeaderTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text="<%$Resources:Resource, Header1 %>"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text="<%$Resources:Resource, Header1 %>"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
Posted
Updated 23-Jan-22 23:34pm
Comments
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 -

C#
GridView1.DataSource = "YOUR_DATASOURCE";
GridView1.DataBind();


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

C#
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
 
v2
you can get from your database like: male, female
bind with datasource


<%# GetLocalResourceObject(Eval("sex"))%>
 
Share this answer
 
Comments
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