how to get value of datarow column on ItemDataBound

Discussion in 'ASP .Net Datagrid Control' 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 in the datagrid's cells

    Problem: no values are passed to the javascript functions.


    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:
    e.Item.Attributes.Add("onclick", "MyClientSideFunction01("
    + ctlSearchResults.SelectedItem.Cells[2].Text) + "," +
    ctlSearchResults.SelectedItem.Cells[3].Text + ")");
    break;
    case 2:
    e.Item.Attributes.Add("onclick", "MyClientSideFunction02("
    + ctlSearchResults.SelectedItem.Cells[2].Text) + "," +
    ctlSearchResults.SelectedItem.Cells[3].Text + ")");
    break;
    default:
    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

    Bhuva Guest

    Hi John,

    Instead of SelectedItem.Cells[1].Text, use e.Item.Cells[1].Text to pass
    the datagrid values to javascript function.

    Here is the modified code.

    try
    {
    if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem )
    {
    int myType =Convert.ToInt32(e.Item.Cells[0].Text);
    switch ( myType )
    {
    case 1:
    e.Item.Attributes.Add("onclick", "Function1('"+
    e.Item.Cells[1].Text +"','" +e.Item.Cells[2].Text + "');");

    break;
    case 2:
    e.Item.Attributes.Add("onclick", "Function2('"+
    e.Item.Cells[1].Text +"','" +
    e.Item.Cells[2].Text + "');");
    break;
    default:
    e.Item.Attributes.Add("onclick", "Function3('"+
    e.Item.Cells[1].Text +"','" +
    e.Item.Cells[2].Text + "');");
    break;
    }
    }
    }

    -Bhuva
    [www.syncfusion.com
    http://www.syncfusion.com/faq/aspnet/default.aspx]
    Bhuva, Jun 19, 2006
    #2
    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. Chet
    Replies:
    3
    Views:
    149,549
  2. Nathan Sokalski
    Replies:
    5
    Views:
    5,696
    Elton Wang
    Sep 25, 2005
  3. orenl
    Replies:
    1
    Views:
    629
    Eliyahu Goldin
    Dec 4, 2006
  4. Nathan Sokalski

    Accessing the current DataRow of the DataSource from ItemDataBound

    Nathan Sokalski, Sep 22, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    153
    Elton Wang
    Sep 25, 2005
  5. Nathan Sokalski

    Accessing the current DataRow of the DataSource from ItemDataBound

    Nathan Sokalski, Sep 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    146
    Elton Wang
    Sep 25, 2005
Loading...

Share This Page