Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found a good solution here: <a href="http://www.trirand.net/forum/default.aspx?g=posts&amp;t=168" rel="nofollow noreferrer">http://www.trirand.net/forum/default.aspx?g=posts&amp;t=168</a></p> <p>The idea is to handle the <code>CellBinding</code> event on the grid, and look up the text corresponding to the ID that the cell contains.</p> <pre><code>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); } } </code></pre> <p>The implementation of <code>LookupText</code> will depend on your situation; you might look through the column's <code>EditValues</code> (e.g. <code>1:One;2:Two;3:Three</code>), or you might look it up in your data.</p> <p>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. </p> <pre><code>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) &gt; 0 Then Result &amp;= ";" Result &amp;= Row(0) &amp; ":" &amp; 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 </code></pre> <p>You just need to call <code>DropdownColumn.Init(MyGrid)</code> on this column from the Grid's <code>init</code> event. Hope this helps someone.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload