ht get column in DataRowItem of datagrid at OnItemDataBound

Discussion in 'ASP .Net' started by xzzy, Jun 18, 2006.

  1. xzzy

    xzzy Guest

    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
     
    xzzy, Jun 18, 2006
    #1
    1. Advertising

  2. xzzy

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
     
    Teemu Keiski, Jun 18, 2006
    #2
    1. Advertising

  3. xzzy

    xzzy Guest

    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
     
    xzzy, Jun 18, 2006
    #3
  4. xzzy

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Teemu Keiski, Jun 18, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio D'Ottavio
    Replies:
    1
    Views:
    2,733
    Antonio D'Ottavio
    Sep 19, 2005
  2. Steven
    Replies:
    1
    Views:
    1,651
    Simon
    Jul 9, 2003
  3. Girish
    Replies:
    2
    Views:
    2,851
    Girish
    Jul 8, 2005
  4. ITnerd
    Replies:
    1
    Views:
    146
    Giorgio Parmeggiani
    Nov 2, 2003
  5. David A. Coursey

    Refrence image in datagrid with OnItemDataBound

    David A. Coursey, Oct 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    136
    Eric Cherng
    Oct 6, 2004
Loading...

Share This Page