ht get column in DataRowItem of datagrid at OnItemDataBound

X

xzzy

For each row in a dataset bound to a datagrid, each row can differ by MyType
( ie 1, 2, 3, . . . ).

for different MyType, I need to call different javascript functions and pass
the values corresponding DataRow of the datagrid's cells

Problem: no values are passed to the javascript functions,
or said another way,
how does one get the value of a column in the DataRowItem of a
DataGrid at OnItemDataBound?

protected void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs
e)
{
try
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
int myType =
Convert.ToInt32(ctlSearchResults.SelectedItem.Cells[1].Text);
switch ( myType )
{
case 1:

//Problem:
// These do not work:
// 1. ctlSearchResults.SelectedItem.Cells[2].Text, or
// 2. DataBinder.Eval(Container.DataItem, "MyColumn"), or
// 3. (DataRowView)Container.DataItem, etc.
//
e.Item.Attributes.Add("onclick",
"MyClientSideFunction01("+ ctlSearchResults.SelectedItem.Cells[2].Text) +
"," + ctlSearchResults.SelectedItem.Cells[3].Text + ")");
break;


Thank you,

John
 
T

Teemu Keiski

DataRowView rview = (DataRowView)e.Item.DataItem;
string textValue = rview["columnName"].ToString();
 
X

xzzy

thank you for pointing me toward the answer, this works:

System.Data.Common.DbDataRecord rview =
(System.Data.Common.DbDataRecord)e.Item.DataItem;
string myString = rview["MyColumn"].ToString();

John
 
T

Teemu Keiski

Yup,

that is when binding to a data reader. With DataTable/DataView it's
DataRowView
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top