Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
Get Row data in ItemCommand event
posted

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.

Parents
  • 2535
    Verified Answer
    Offline posted

    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.

Reply Children
No Data