Skip to content

Get Row data in ItemCommand event

New Discussion
Gloria Santin
Gloria Santin asked on Feb 25, 2020 7:20 PM

My webdatagrid has a column of links.  When the user clicks the link an ItemCommand event is fired.  Within that event I would like to retrieve the data from the other bound columns. This is my markup:

<ig:WebHierarchicalDataGrid ID=”WebHierarchicalDataGrid1″ runat=”server”
Height=”600px” Width=”875px”
Key=”SqlDataSource1_DefaultView” DataMember=”SqlDataSource1_DefaultView”
DataSourceID=”WebHierarchicalDataSource1″ AutoGenerateBands=”False”
AutoGenerateColumns=”False” StyleSetName=”Windows7″ DataKeyFields=”DrNum”
onitemcommand=”WebHierarchicalDataGrid1_ItemCommand”
oninitializerow=”WebHierarchicalDataGrid1_InitializeRow”>
<Columns>
<ig:BoundDataField DataFieldName=”ID” Key=”ID” Hidden=”true”>
<Header Text=”ID” />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName=”DrNum” Key=”DrNum” Hidden=”true”>
<Header Text=”DrNum” />
</ig:BoundDataField>
<ig:TemplateDataField Key=”LastName”>
<Header Text=”Last Name” />
<ItemTemplate>
<asp:LinkButton ID=”LinkButton1″ runat=”server”
Text='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem,”LastName”) %>’
CommandName=”GetInfo” CommandArgument='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem,”ID”) %>’ />
</ItemTemplate>
</ig:TemplateDataField>
<ig:bounddatafield datafieldname=”FirstName” key=”FirstName”>
<header text=”First name” />
</ig:bounddatafield>
<ig:BoundDataField DataFieldName=”MiddleName” Key=”MiddleName”>
<Header Text=”M. Name” />
</ig:BoundDataField>
</Columns>
</ig:WebHierarchicalDataGrid>

This is my ItemCommand Event:

protected void WebHierarchicalDataGrid1_ItemCommand(object sender, Infragistics.Web.UI.GridControls.HandleCommandEventArgs e)
{
if (e.CommandName == “GetInfo”)
{
string ID = e.CommandArgument.ToString();
Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid grid = (Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid)sender;
//HOW DO I GET THE VALUES OF THE COLUMNS BELOW?
string tstrFullName = grid.Columns[“FirstName”].ToString() + ” ” + grid.Columns[“MiddleName”].ToString() + ” ” + grid.Columns[“LastName”].ToString();

}
}

The event is triggered and the e.CommandArgument is the ID of the row.

I need to get the values of the other columns.  How do I do that?

THanks.

Sign In to post a reply

Replies

  • 0
    Nadia Robakova
    Nadia Robakova answered on May 29, 2015 7:42 AM

    Hello Gloria,

    Thank you for using our forum.

    You can set CommandArgument to be the row index:

    <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem,"Data") %>' CommandName="GetInfo" CommandArgument='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).Item,"Row.Index") %>' />

    When you have the row index you can get all the cells values in it:

    protected void WebHierarchicalDataGrid1_ItemCommand(object sender, HandleCommandEventArgs e)
        {
            if (e.CommandName == "GetInfo")
            {
               int rowIndex = int.Parse(e.CommandArgument.ToString());
                Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid grid = (Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid)sender;
                string ID = grid.Rows[rowIndex].Items.FindItemByKey("ID").Value.ToString();

                //HOW DO I GET THE VALUES OF THE COLUMNS BELOW?
                //string tstrFullName = grid.Columns["FirstName"].ToString() + " " + grid.Columns["MiddleName"].ToString() + " " + grid.Columns["LastName"].ToString();
                string firstName = grid.Rows[rowIndex].Items.FindItemByKey("FirstName").Value.ToString();
                string middleName = grid.Rows[rowIndex].Items.FindItemByKey("MiddleName").Value.ToString();
                string lastName = grid.Rows[rowIndex].Items.FindItemByKey("LastName").Value.ToString()
                string tstrFullName = firstName + " " + middleName + " " + lastName;
            }
        }

    Let me know if I may be of further assistance.

    • 0
      Nadia Robakova
      Nadia Robakova answered on Jun 3, 2015 9:54 AM

      Hello,

      I'm just following up to see if you need any further assistance with this issue. If so please let me know.

      • 0
        Gloria Santin
        Gloria Santin answered on Jun 3, 2015 1:37 PM

        I do not need assistance for this issue.

        Thank you.

        Gloria

      • 0
        Olga Postilnik
        Olga Postilnik answered on Feb 25, 2020 7:20 PM

        Do you know why this code doesn't work with paging? RowIndex is used to get the value not relative to the visible part of the dataset but the whole dataset. If I select row number 3 on page 8t, the code would get the value row 3, not 8 times page size plus three.

        Thanks.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Gloria Santin
Favorites
0
Replies
4
Created On
Feb 25, 2020
Last Post
6 years, 1 month ago

Suggested Discussions

Created by

Created on

Feb 25, 2020 7:20 PM

Last activity on

Feb 26, 2026 7:14 PM