Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 263357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:35:42+00:00 2026-05-11T22:35:42+00:00

I have a question: I have two MSSQL tables, items and states, that are

  • 0

I have a question:

I have two MSSQL tables, items and states, that are linked together via a stateid:

    STATES                  ITEMS
-------------    ---------------------------
| id | name |    | id | name | ... | stateid
  V                                     ^
  |_____________________________________|

So Items.StateID is related to State.ID. In my current situation I have a GridView that is databound to a LinqDataSource, which references the Items table. The GridView has two columns, one is Name and the other is StateID. I want to be able to pull the name of the state associated with the StateID out from the state table so that is displayed instead of the StateID.

Thanks in advance!

EDIT

Here is the grid/datasource:

<asp:LinqDataSource ID="ItemViewDataSource" runat="server" ContextTypeName="GSFyi.GSFyiDataClassesDataContext"  EnableDelete="true" TableName="FYI_Items" />

<h2 class="gridTitle">All Items</h2>
<telerik:RadGrid ID="ItemViewRadGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ItemViewDataSource" GridLines="None" AllowAutomaticDeletes="True" EnableEmbeddedSkins="False" OnItemDataBound="itemsGrid_ItemDataBound">
<HeaderContextMenu>
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView DataKeyNames="id" DataSourceID="ItemViewDataSource" CommandItemDisplay="None" CssClass="listItems" Width="98%">
    <RowIndicatorColumn>
        <HeaderStyle Width="20px" />
    </RowIndicatorColumn>
    <ExpandCollapseColumn>
        <HeaderStyle Width="20px" />
    </ExpandCollapseColumn>
    <Columns>
        <telerik:GridTemplateColumn ItemStyle-CssClass="gridActions edit" UniqueName="Edit">
            <ItemTemplate>
                <asp:HyperLink ID="edit" runat="server" Text="Edit"></asp:HyperLink>
            </ItemTemplate>
<ItemStyle CssClass="gridActions edit"></ItemStyle>
        </telerik:GridTemplateColumn>
        <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this item?" ConfirmDialogType="RadWindow" ButtonType="LinkButton" ItemStyle-CssClass="gridActions delete"  CommandName="Delete" >
<ItemStyle CssClass="gridActions delete"></ItemStyle>
        </telerik:GridButtonColumn>
        <telerik:GridBoundColumn DataField="name" HeaderText="Item Name" SortExpression="name"
            UniqueName="name">
        </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="State" UniqueName="state">
                        <ItemTemplate>
                            <asp:Label ID="stateLbl" runat="server" Text='<%# Eval("stateid") %>' />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
    </Columns>
</telerik:RadGrid>

And the current code-behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Cms.Web.UI;
using Telerik.Web.UI;

public partial class Custom_Modules_GSFyi_Backend_Views_ItemsListView : ViewModeUserControl<ItemsView>
{
    protected void Page_Load(object sender, EventArgs e)
    {
        addNewItem.NavigateUrl = CreateHostViewCommand("ItemsInsertView",null,null);
    }
    protected void itemsGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
        {
            var item = (GSFyi.FYI_Item)e.Item.DataItem;
            HyperLink edit = (HyperLink)e.Item.FindControl("edit");
            edit.NavigateUrl = CreateHostViewCommand("ItemsEditView", item.id.ToString(), null);

        }
    }
}

Does this help at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:35:42+00:00Added an answer on May 11, 2026 at 10:35 pm

    Assuming you’ve defined the relationship in your LINQtoSQL data classes and the LINQDataSource control is pointing at your Items entity you should be able to use the following databinding syntax directly in your GridView markup:

    <asp:GridView ID="ItemsGridView" runat="server" DataKeyNames="id" DataSourceID="ItemsLinqDataSource">
        <Columns>
            <asp:TemplateField>
                        <ItemTemplate>
                                <%# Eval("states.name") %>
                        </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
    <asp:LinqDataSource ID="ItemsLinqDataSource" runat="server" ContextTypeName="DataClassesDataContext" TableName="items"></asp:LinqDataSource>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have four tables user-question contains two columns: questionID, userID, the questions that the
If I have two tables in mysql that have similar columns... TABLEA id name
I have a mssql stored procedure question for you experts: I have two tables
that´s my first question in stackoverflow . I have two MYSQL tables: categories and
I have two examples I have a question about. Let me explain via some
I have a question regarding the design of two tables. Table 1: The main
A quick technical question- I have two queries that output some of the same
I have MySQL database with two tables: users and items. They look like this:
I have two tables in MySQL that I'm comparing with the following attributes: tbl_fac
I have two MySQL tables describing data that can be extended into subclasses, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.