Rob
Rob

Reputation: 2472

ASP.NET do not show eval in page - ASPxGridView

I have hopefully a simple question. I have a ASPxGridView that I need to pull data from and pass it to a function. A simple way I figured to do this is to use a session variable.

But when I do the Eval binding it shows the characters on screen (as well as putting them into the variable). How do I remove the characters from the screen? Or maybe there is a easier way to do this.

Code is here (real meat is 4th line down):

            <dx:GridViewDataButtonEditColumn Caption="" Name="Schedule" 
            VisibleIndex="11">
            <DataItemTemplate>
             <%# Session["PatientID"] = Eval("PatientID")%>
                  <dx:ASPxButton ID="ASPxButton1"  runat="server" Text="Schedule"  OnClick="Button_Click" >
                  </dx:ASPxButton>
            </DataItemTemplate>

        </dx:GridViewDataButtonEditColumn>

Upvotes: 0

Views: 1239

Answers (3)

Rob
Rob

Reputation: 2472

I am adding the functional code here. Thanks all! Using command worked great.

protected void Button_Click(object sender, CommandEventArgs e)
{
    string patID = e.CommandArgument.ToString();
    Response.Redirect("schedule.aspx?PatientID=" + patID);
}


    <dx:GridViewDataButtonEditColumn Caption="" Name="Schedule" 
        VisibleIndex="11">
        <DataItemTemplate>
            <dx:ASPxButton ID="ASPxButton1"  runat="server" Text="Schedule"  
CommandName = "PatientID" CommandArgument = '<%# Eval("PatientID")%>' OnCommand="Button_Click" >
                </dx:ASPxButton>
            </DataItemTemplate>
        </dx:GridViewDataButtonEditColumn>

Upvotes: 0

user240141
user240141

Reputation:

Try this

 <dx:GridViewDataButtonEditColumn Caption="" Name="Schedule" VisibleIndex="11">
     <DataItemTemplate>
       <dx:ASPxButton ID="ASPxButton1"  
        runat="server" Text="Schedule"  
        OnClick="Button_Click" 
        CommandName='SomeCoolCommandName' 
        CommandArgument='<%#Eval("PatientID")'>
       </dx:ASPxButton>
      </DataItemTemplate>
 </dx:GridViewDataButtonEditColumn>

On it rowcommand or Itemcommand event check for command and do something..

protected YourGrid_ItemCommand(sender, e)
{
   if(e.CommandName.Equals("SomeCoolCommandName"))
   {
       var id = Convert.ToInt32(e.CommandArgument); // Give you your Patient ID
       // do whatever you want to do with your ID
   }
}

Upvotes: 1

Krishanu Dey
Krishanu Dey

Reputation: 6406

Try to put a hidden field and bind its value like following

<asp:HiddenField ID="hdnPatientID" runat="server" Value='<%# Eval("PatientID")%>' />

Upvotes: 1

Related Questions