asp.net find datatable item - datatable

hi i have a datatable with 2 columns one for id(unique) and another for "description". now i have a dropdownlist with "description" from the same datatable mentioned above. when users selects a particular item from description, i need to pick the id corresponding to the selected value. what is the easiest way to achieve this, should i use a foreach or datatable find method.

You should set the Dropdownlist's DataTextField to the Description and its DataValueField to the ID.
MyDropDownList.DataSource = MyDataTable
MyDropDownList.DataTextField = "Description"
MyDropDownList.DataValueField = "ID"
MyDropDownList.DataBind()
Then you can get the ID via MyDropDownList.SelectedValue.

firstly, you might want to give some more information- what programming language you're using (I'm assuming C#)
now, regarding what you've described, you probably want to use the datatable's find method, or, preferrably- use LINQ on the datatable.
table.First(x=> x.description == desc).Id;
(note that this code assumes that an element with a matching description exists. If such an element may not exist- use FirstOrDefault and check the return result for null value).
good luck.

A quick example of this can be found here
http://forums.asp.net/p/1590755/4029475.aspx
Using the answer provided above yoyuu would then use dropdownlist.selecteditem.value, hope this helps.

Related

Add map rule to predefined data style (refer to "value of this data item")

in our reporting the value of data elements will be rewrited with "-" in the case of Null.
Can I put this mapping rule to the predefined style of the "data" element ? I tried it, but I don't know who to implement the later reference to "The_current_row_value". Has anyone a idea?
Thanks a lot.
Instead of trying to use an edit tool in the report, use SQL's isnull() to convert null values to whatever value you desire.
ISNULL (Transact-SQL)
If for some reason that does not appeal to you, use a computed column in your BIRT data set, and define the value with Java Script.

primefaces datatable multiple sort with specified name on id

I want to have multiple sort on datatable. I find below link that seems more match on my case. Initial sortorder for Primeface datatable with multisort
But I have one field that have specified sorting. I have only three different values. e.g. TCS(first in sorting), School-input (second), self-input (third). Their sorting are not on letters as you see. How to handle this?? Do you have any suggestions to help me??
I have solved by adding one more parameter in the class of typeId which will be sorting. typeId is hardcoded assigned to different type string.

Laravel 4 - Find item by column

I was wondering if i could get a bit of help.
Is there any way to change the 'find' parameters to search in another column?
If i use
$test = Model::find($id)
This searches the ID field of a table, but what if i want to search by the token column instead.
Is there any way of doing that?
Cheers,
You can use:
$test = Model::where($column, '=', $value)->first()
The find method is attached to the primary key. You could maybe override it in your model, but you have other ways to achieve your goal without overriding it.

YUI DataTable - multiple columns filtering

I know, that it is possible to filter dataTable Control on client as it is shown in this exaple:
http://developer.yahoo.com/yui/examples/datatable/dt_localfilter.html
Is it also possible to filter more columns? I'd like to have 2 textfields, and when I type sth to the first one, DataTable would filter according to the 'areacode' (from the example) and when I type sth to the second one, DataTable would filter according to the 'state'.
Is this possible somehow? Thanks for any help.
The simplest way to modify the existing example would be to build a request string that contains the information for each text box. For example (column1=a&colum2=b), modify the doBeforeCallback to split the request and do the filtering for each column.

changing JQgrid column name dynamically

I just need to rename JQgrid column dynamically as per user selection from a list of options. How can I do that?
You can use this syntax:
jQuery("#grid1").jqGrid('setLabel', 0, 'NewLabel');
This will change first column name to NewLabel in your grid with id=grid1.
The latest version of jqGrid (4.1+ - possibly earlier) no longer appears to support the column index based setLabel approach described by Galichev, a columnName based approach is provided instead:
jQuery("#grid1").jqGrid('setLabel', 'columnName', 'NewLabel');
See the jqGrid Methods wiki for more information.
I've left the previous answer unedited as this approach may be valid in versions prior to 4.1.
According to the jqGrid Documentation, colNames cannot be changed after the grid is created.
However, you might be able to simulate a column name change by using several columns. Then you can hide all of them except a single one which will be shown to the user. When the user selects another, just swap in the selected column. For example, if valid columns are [A, B, C, D] you might start by only showing A. Then if the user chooses C, hide A and show C. The main disadvantage to this approach is that you will need to copy the same data to many columns, however.
Update
Per Galichev's answer, you can use the setLabel method to rename a column header.
*setLabel : * colname the name of the column (this parameter can be a number (the index of the column) beginning from 0
However the index param does not work with version 4.1 and above.
Jqgrid uptop version 4.0
$(tableId).jqgrid("setLabel", 0, "BBBBB");
Jqgrid version 4.1 and above
Try using these
$(tableId).setLabel("ColumnName", "AAAAA");
or
$(tableId).jqgrid("setLabel", "ColumnName", "BBBBB");
JQGrid1.Columns.FromDataField(ColumnName).HeaderText = ColumnName;
I gave my column name a div
'<div id="DateDivId">Date</div>'
Then I just changed it the normal way, getElementById, change contents.

Resources