473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

ht get column in DataRowItem of datagrid at OnItemDataBound

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.Cell s[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


Jun 18 '06 #1
3 1440
DataRowView rview = (DataRowView)e.Item.DataItem;
string textValue = rview["columnName"].ToString();

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"xzzy" <mr********@comcast.net> wrote in message
news:F8******************************@comcast.com. ..
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.Cell s[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

Jun 18 '06 #2
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
Jun 18 '06 #3
Yup,

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

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"xzzy" <mr********@comcast.net> wrote in message
news:Ta******************************@comcast.com. ..
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

Jun 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
4
by: John Doe | last post by:
Hi I want to convert a column to a link. All examples I have seen works with bound columns. I have the following grid: <asp:datagrid runat="server" id="__theDetailsGrid" cellpadding="2"...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
2
by: MattB | last post by:
I'm trying to set a column name when my datagrid is being rendered. I've used the OnItemDataBound event before, so I decided to try and use it again here. The problem I'm having is I'm trying to...
0
by: carlos perez | last post by:
Two thins There is a field called explanation. I need to detect if the field is empty the buttoncolumn must be active for that row if its already filled the user cant join more data. I have...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
4
by: Nicky | last post by:
hi, all I got another quesiton, in my DataGrid control, I want to have a hidden column which will contian an ID value, I don't want to display this ID value to user, but I need it when user click...
2
by: Baren | last post by:
Hi!, I am using the following CSS class for the DataGrid Head column wherein i am sorting the recrods. The style works fine.. By default it puts an underline for each header column. The underlin...
9
by: Roy | last post by:
Hey all, On my html page I have a datagrid with the column: <boundColumn datafield="xyz" visible = false> </boundColumn> In my code behind, within item data bound event, I dynamically set the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.