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

  • Home
  • SEARCH
  • 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 638587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:44:55+00:00 2026-05-13T20:44:55+00:00

Suppose Items and ItemTypes have numeric primary keys ItemID and ItemTypeID. Each Item is

  • 0

Suppose Items and ItemTypes have numeric primary keys ItemID and ItemTypeID. Each Item is assigned an ItemType.

I have a JQGrid to edit Items. When not in edit mode, I would like to see the name of the ItemType, not the ItemTypeID:

    TYPE       | TITLE
    -----------+--------------------
    Category A | Item 1
    Category A | Item 2
    Category B | Item 3
    Category B | Item 4

In edit mode, I want to see a dropdown that displays the ItemType text, but that returns the ItemTypeID to the server.

Here’s what I have so far (using the ASP.NET wrapper for JQGrid):

<trirand:jqgrid id="Grid1" runat="server" ... >
    <columns>
        <trirand:jqgridcolumn datafield="ItemID" editable="false" visible="false" width="50" primarykey="true" />
        <trirand:jqgridcolumn datafield="ItemTypeID" editable="true" edittype="DropDown" editorcontrolid="ItemTypes" />
        <trirand:jqgridcolumn datafield="Title" editable="true" sortable="true" />
        ...
    </columns>
</trirand:jqgrid>
<asp:sqldatasource runat="server" id="ItemTypesDatasource" connectionstring="<%$ ConnectionStrings:Main %>" selectcommand="Select ItemTypeID,Title from ItemTypes order by Title" />
<asp:dropdownlist runat="server" id="ItemTypes" datasourceid="ItemTypesDatasource" datavaluefield="ItemTypeID" datatextfield="Title" />

The problem is that when not in edit mode, it displays the numeric ItemTypeID, rather than the text labels:

    TYPE       | TITLE
    -----------+--------------------
    100123     | Item 1
    100123     | Item 2
    100124     | Item 3
    100124     | Item 4

Is there any way to have JQGrid respect the distinction between DataValueField and DataTextField? (Either using the jQuery API or the ASP.NET plugin.)

  • 1 1 Answer
  • 1 View
  • 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-13T20:44:56+00:00Added an answer on May 13, 2026 at 8:44 pm

    Found a good solution here: http://www.trirand.net/forum/default.aspx?g=posts&t=168

    The idea is to handle the CellBinding event on the grid, and look up the text corresponding to the ID that the cell contains.

    protected void JQGrid1_CellBinding(object sender, Trirand.Web.UI.WebControls.JQGridCellBindEventArgs e)
       {
          if (e.ColumnIndex == 1) // index of your dropdown column
          {
             e.CellHtml = LookupText(e.CellHtml);
          } 
       }
    

    The implementation of LookupText will depend on your situation; you might look through the column’s EditValues (e.g. 1:One;2:Two;3:Three), or you might look it up in your data.

    I’ve wrapped all of this logic into a custom column class (in VB.NET) that also populates the dropdown based on a SQL command you give it.

    Public Class JqGridDropDownColumn
        Inherits Trirand.Web.UI.WebControls.JQGridColumn
    
        Private _SelectCommand As String
        '' /* The SQL command used to populate the dropdown. */
        '' /* We assume that the first column returned contains the value (e.g. BudgetID)  and the second column contains the text (e.g. Title). */
        Public Property SelectCommand() As String
            Get
                Return _SelectCommand
            End Get
            Set(ByVal value As String)
                _SelectCommand = value
            End Set
        End Property
    
        Private _DropDownNullText As String
        Public Property DropDownNullText() As String
            Get
                Return _DropDownNullText
            End Get
            Set(ByVal value As String)
                _DropDownNullText = value
            End Set
        End Property
    
        Private WithEvents Grid As JQGrid
        Private DropDownValues As DataTable
    
        Sub Init(g)
            Grid = g
            DropDownValues = ExecuteDataset(cs, CommandType.Text, Me.SelectCommand).Tables(0)
            DropDownValues.PrimaryKey = New DataColumn() {DropDownValues.Columns(0)}
            Me.EditValues = BuildEditValues(DropDownValues)
        End Sub
    
        '' /* Builds a string of the form "1:One;2:Two;3:Three" for use by the EditValues property. */
        '' /* This assumes that Table consists of two columns corresponding to the Value (e.g. BudgetID) and Text (e.g. Title), in that order. */ 
        Protected Function BuildEditValues(ByVal Table As DataTable) As String
            Dim Result As String = ""
            If Not String.IsNullOrEmpty(Me.DropDownNullText) Then
                Result = String.Format(":{0}", Me.DropDownNullText)
            End If
            For Each Row As DataRow In Table.Rows
                If Len(Result) > 0 Then Result &= ";"
                Result &= Row(0) & ":" & Row(1)
            Next
            Return Result
        End Function
    
    
        Private Sub Grid_CellBinding(ByVal sender As Object, ByVal e As Trirand.Web.UI.WebControls.JQGridCellBindEventArgs) Handles Grid.CellBinding
            '' /* Display the text (e.g. Title) rather than the value (e.g. BudgetID) */
            If Grid.Columns(e.ColumnIndex) Is Me Then
                e.CellHtml = LookupText(e.CellHtml)
            End If
        End Sub
    
        Private Function LookupText(ByVal Value As String) As String
            Dim MatchingRow As DataRow = DropDownValues.Rows.Find(Value)
            If MatchingRow IsNot Nothing Then
                Return MatchingRow(1) '' /* Column 1 is assumed to contain the text */
            Else
                Return ""
            End If
        End Function
    End Class
    

    You just need to call DropdownColumn.Init(MyGrid) on this column from the Grid’s init event. Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have multiple roles, each one defining a set of items: package A;
I have the following XSLT question: Suppose I have this XML <items> <item> <type>dog</type>
Suppose we have a table A: itemid mark 1 5 2 3 and table
Suppose I have two items, a and b, that compare the same. So a
Suppose I have some serially numbered items that are 1-n units wide, that need
Suppose I have a list of items (e.g., Posts) and I want to find
Suppose we have a list of items with an integer: USA: 3 people Australia:
Suppose I have a set of tuples like this (each tuple will have 1,2
Suppose I have a content type, Folder, with 4 items. + MyObject - Child1
Suppose I have a combobox where items are binded to an array of strings.

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.