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
295
ItemTemplate ImageButton CommandArgument
posted

I have a WHDG that is bound to a dataset and has one TemplateDataField and one ItemTemplate with an ImageButton. I am setting the CommandArgument of the ImageButton to the value of a column in my data source. I can set it to any column in that dataset except the column that is referenced in the DataKeyFields property of the grid. When I use that column, which is the primary key of the dataset, the CommandArgument that I get server side is a negative (-) number and is not the proper value of that record. It appears to be the index of the row that contains the imagebutton.

Server Side Handler 

 

protected

 

 

void btnGoClientDetails_Command(object sender, EventArgs e)

{

 

 

 

 

 

 

 

ImageButton img = (ImageButton)sender;

 

 

 

 

int WorkItemPCNId = 0;

 

 

 

if (img != null){ 

WorkItemPCNId =

 

Convert.ToInt32(img.CommandArgument);

 

}

}

Grid code

 

 

 

 

 

 

 

 

 

 

 

<

 

 

 

ig:WebHierarchicalDataGrid ID="PCNGrid" runat="server" Height="700px" Width="1100px"

 

 

 

AutoGenerateBands="False"

 

 

 

AutoGenerateColumns="False" DataMember="ObjectDataSource1_DefaultView"

 

 

 

DataSourceID="WebHierarchicalDataSource1" Key="ObjectDataSource1_DefaultView"

 

 

 

OnDataBound="PCNGrid_DataBound" DataKeyFields="WorkItemPCNID" >

 

 

 

<Columns

>

 

 

 

<ig:BoundDataField DataFieldName="WorkItemPCNID" Key="WorkItemPCNID" Hidden

="true">

 

 

 

<Header Text="WorkItemPCNID"

/>

 

 

 

</ig:BoundDataField

>

 

 

 

<ig:BoundDataField DataFieldName="SourcePCNId" Key="SourcePCNId" Hidden

="true">

 

 

 

<Header Text="SourcePCNId"

/>

 

 

 

</ig:BoundDataField

>

 

 

 

 

 

 

 

 

 

<ig:TemplateDataField Key="SelectRow" Hidden="false" Width

="30px">

 

 

 

<ItemTemplate

>

 

 

 

<asp:ImageButton ID="btnGoClientDetails" runat="server" ImageUrl="~/images/ViewDetails.gif" ToolTip="View Details In PIMs Database"

 

 

 

OnCommand="btnGoClientDetails_Command" CommandArgument='<%# Eval("WorkItemPCNID")%>'

/>

 

 

 

</ItemTemplate

>

 

 

 

<Header Text=""

/>

 

 

 

</ig:TemplateDataField

>

...

  • 295
    posted

    Figured it out myself. Was a problem with the dataset. Not the grid.