gridview commandargument on buttonfield pagination used

Posted by ClareBear on Stack Overflow See other posts from Stack Overflow or by ClareBear
Published on 2009-11-03T10:43:45Z Indexed on 2010/04/12 7:03 UTC
Read the original article Hit count: 313

Filed under:
|
|

Hello all,

I am using c#.net

I have a gridview which needs to contain a 'Use' button (appointmentId set as the commandargument).

Source Code

<asp:GridView ID="resultsReturned" runat="server" AllowPaging="True"  
    AutoGenerateColumns="False"
    EnableSortingAndPagingCallbacks="True" 
    OnPageIndexChanged="resultsReturned_PageIndexChanged" 
    onrowcommand="resultsReturned_RowCommand">
    <Columns>    
      <asp:BoundField DataField="UserAppointmentId" HeaderText="App ID" />
      <asp:BoundField DataField="UserBookingName" HeaderText="Booking Name" />
      <asp:TemplateField>
        <ItemTemplate>                
          <asp:Button runat="server" 
            ID="UseButton"
            Text="Use"
            CommandName="Use"
            CommandArgument="UserAppointmentId" />
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
  </asp:GridView>

Code-Behind

protected void resultsReturned_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Use")
    {
        correctAppointmentID.Value = (e.CommandArgument.ToString());
    }
}

This is used for the pagination:

private void BindAppointments()
{
    var results = appointmentRepos.GetBookingIdBySearchCriteria(catgoryid, resultsReturned.PageIndex * resultsReturned.PageSize, -1);

    resultsReturned.DataSource = results;            
    resultsReturned.DataBind();
}

I am binding the appointments to the gridview within the PageLoad/search_Click

This is the error I am receiving:

Callbacks are not supported on TemplateField because some controls cannot update properly in a callback. Turn callbacks off on 'resultsReturned'.

Thanks in advance for any help

Clare

© Stack Overflow or respective owner

Related posts about gridview

Related posts about pagination