I've looked at pages and pages of documentation and forum threads, but I can't seem to get around this issue. Using the WebDataGrid (.NET 3.5) I have a grid with nine or so templated columns. The first column template is a LinkButton; I have that set up for an ItemCommand to process it (gets the detail data and displays it on another web page). I have my CommandName set up, and what I need to do is either pass the container for that row, or the row index, back to the server side ItemCommand method so I can grap some other fields from that row. Basically, in ItemCommand I need to know what row that LinkButton was clicked.
I've tried everything to get the CommandArgument to pass back the record number but nothing works. I tried the idea presented in another thread, using:
CommandArgument="<%# Container.Cell.Row.Index %>"
but that always gives back the error 'Cell' is not a member of 'System.Web.UI.Control'.
So my big question is: In ItemCommand (for a WebDataGrid) how can I either get the current row that the LinkButton was click on (in ItemCommand), or at least get passed back the row index?
I'm frustrated... hope someone can help. Thx.
/Tom
I agree. You should be able to reference the row in question. Passing multiple values in the CommandArgument field is not always feasible. You would want to be able to reference the Grid row and the Data row behind it. If this is not possible, then simply tell us.
The Container needs to be cast to Infragistics.Web.UI.TemplateContainer. You can either store in the CommandArgument a unique identifier of the row, like a data key for example (here DataItem should be used)
CommandArgument=<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "PostId") %>
or reference the actual underlying object. In case of the ItemTemplate it is the cell. To get the row index, something like that can be done (here the Item property should be used):
CommandArgument=<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).Item, "Row.Index") %>
This latter approach however has a problem, the Item property is currently referencing the same object as the DataItem. It's been fixed and the fix is coming up shortly.
Hi,
Iam looking forward to achieve this in C# code behind.(especially the row index part). Could u please provide the same.
<ig:TemplateDataField Key="UnitPrice">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
Text='<%# DataBinder.Eval(DirectCast(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "UnitPrice") %>'
CommandArgument='<%# DataBinder.Eval(DirectCast(Container, Infragistics.Web.UI.TemplateContainer).Item, "Row.Index") %>'>
</asp:LinkButton>
</ItemTemplate>
<Header Text="UnitPrice" />
</ig:TemplateDataField>
Hello,
If you use VB the syntax is as follows: Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server"
Height="420px" Width="937px" DataKeyFields="Report Format"
DataMember="SqlDataSource1_DefaultView"
DataSourceID="WebHierarchicalDataSource1" Key="SqlDataSource1_DefaultView"
AutoGenerateBands="False" AutoGenerateColumns="False"
StyleSetName="Caribbean"
>
<Bands
<ig:Band AutoGenerateColumns="False" DataMember="SqlDataSource2_DefaultView_1"
Key
="SqlDataSource2_DefaultView_1">
<
ExpandButton ImageUrl="~/Trendy/images/igsli_PlusHoverV.gif" HoverImageUrl="~/Trendy/images/igsli_PlusHoverV.gif" PressedImageUrl="~/Trendy/images/igsli_PlusPressV.gif"></ExpandButton
CollapseButton ImageUrl="~/Trendy/images/igsli_MinusPressV.gif" HoverImageUrl="~/Trendy/images/igsli_MinusHoverV.gif" PressedImageUrl="~/Trendy/images/igsli_MinusPressV.gif"></CollapseButton
<Columns
<ig:BoundDataField DataFieldName="Report Format" Key="Report Format"
Hidden
="True">
<Header Text="Report Format"
/>
</ig:BoundDataField
<ig:BoundDataField DataFieldName="TestName" Key="TestName" Width
="500px">
<Header Text="TestName"
<ig:BoundDataField DataFieldName="RtPageSize" Key="RtPageSize" Hidden
<Header Text="RtPageSize"
</Columns
</ig:Band
</Bands
<ExpandButton HoverImageUrl="~/Trendy/images/igsli_PlusHoverV.gif"
ImageUrl="~/Trendy/images/igsli_PlusHoverV.gif"
PressedImageUrl="~/Trendy/images/igsli_PlusPressV.gif"
<CollapseButton HoverImageUrl="~/Trendy/images/igsli_MinusHoverV.gif"
ImageUrl="~/Trendy/images/igsli_MinusPressV.gif"
PressedImageUrl="~/Trendy/images/igsli_MinusPressV.gif"
<GroupingSettings GroupAreaVisibility
="Hidden">
</GroupingSettings
Width
="300px">
<ig:BoundDataField DataFieldName="RtPageSize" Key="RtPageSize" Hidden="True"
="50px">
<ig:TemplateDataField Key
="PrintReport">
<ItemTemplate
<igtxt:WebImageButton ID="WebImageButton" runat="server" Height="18px"
Text="Print Report" UseBrowserDefaults="False" AutoSubmit
="False">
<RoundedCorners DisabledImageUrl="ig_butXP5wh.gif"
FocusImageUrl="ig_butXP3wh.gif" HoverImageUrl="ig_butXP2wh.gif"
ImageUrl="ig_butXP1wh.gif" MaxHeight="80" MaxWidth="400"
PressedImageUrl="ig_butXP4wh.gif" RenderingType="FileImages"
<ClientSideEvents Click="btnPrintPatReport_Click"
<Appearance
<Image Url="./Images/rtg_print.gif"
<ButtonStyle Font-Names="Verdana" Font-Size
="Larger">
</ButtonStyle
</Appearance
</igtxt:WebImageButton
</ItemTemplate
<Header Text="TemplateField_0"
</ig:TemplateDataField
<Behaviors
<ig:Activation
</ig:Activation
<ig:Selection
</ig:Selection
<ig:Sorting
</ig:Sorting
</Behaviors
</ig:WebHierarchicalDataGrid
this is my code can u pls tell me how to retrive particular cell value in template(button) click
Are you using VB?