views:

467

answers:

1

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

A: 

Try the following:

 <asp:Button runat="server" 
ID="UseButton" Text="Use" CommandName="Use"
CommandArgument='<%# DataBinder.Eval(Container,"DataItem.UserAppointmentId") %>' />

and Set EnableSortingAndPagingCallbacks="False"

Himadri
It is still causing the same problem: Callbacks are not supported on TemplateField because some controls cannot update properly in a callback. Turn callbacks off on 'resultsReturned'. This error message occurs here: resultsReturned.DataBind();
ClareBear
I changed EnableSortingAndPagingCallbacks="False" and got the following error:Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
ClareBear