Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PostBackUrl with a ID attached to it

Posted on 2009-05-14
6
752 Views
Last Modified: 2013-12-17
Hi,

On my gridview I have a row that has an imagebutton that should take to my evaluationpage.. the problem is that I have no clue how to post the participantID
like this:
PostBackUrl="~/SurveyData/evaluation.aspx?r=ParticiapntID"   ParticiapntID = int

I've tried this:
<asp:ImageButton ID="lnkSelect2" PostBackUrl='evaluation.aspx?r=<% eval(ParticipantID) %>' runat="server" ImageUrl="~/Images/icons/pencil.gif" ToolTip="Edit Evaluation"  />
and I got this on the url: /evaluation.aspx?r=%3C%ParticipantID%%3E


any idea?
0
Comment
Question by:Romacali
6 Comments
 
LVL 6

Expert Comment

by:ViceroyFizzlebottom
ID: 24390519
Try using eval(HttpUtility.HTMLDecode(ParticipantID))
0
 
LVL 6

Expert Comment

by:ViceroyFizzlebottom
ID: 24390528
Actually, disregard my previous post. I didn't read your question closely enough.
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24390566
As per my understanding, the code for handling postbacks from the controls within GridView are handled within RowCommand event mostly although there are specific events available for editing, deleting, etc.
With the RowCommand event of the GridView, write the following code.
1. You have to set the CommandName and CommandArguemnt properties of the ImageButton. CommandName can be set at design time whiel CommandArgument must be set at Runtime.
2. Make use of DataKeyNames property of the GridView and set its value to ParticipantID which actually is your row-key. This is utilized for setting CommandArguemnt on ImageButton within RowDataBound event.
3. Finally, within RowCommand, read the value of CommandArguement and do as necessary.

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
 
	If e.Row.RowType = DataControlRowType.DataRow Then
 
		CType(e.Row.Cells(0).FindControl("btnDoSomething"), ImageButton).CommandArgument = GridView1.DataKeys(e.Row.RowIndex).Values(0).ToString()
 
	End If
 
End Sub
 
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
 
	If e.CommandName = "DoSomething" Then
 
		Dim intParticipantId As Integer = CInt(e.CommandArgument)
		'Do anything you wish to do there
 
	End If
 
End Sub

Open in new window

0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 200 total points
ID: 24390594
Sorry I posted the code with VB. Check the code below:
//RowDataBound event code
if (e.Row.RowType == DataControlRowType.DataRow)
{   
    ((ImageButton)e.Row.Cells(0).FindControl("btnDoSomething")).CommandArgument = GridView1.DataKeys(e.Row.RowIndex).Values(0).ToString();
}
 
//RowCommand evnet code
if (e.CommandName == "DoSomething")
{
    int intParticipantId = (int)e.CommandArgument;
    //Do anything you wish to do there
}

Open in new window

0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
ID: 24391589
before i can answer i will like to ask another question
what is your exeact requirement of doing this

i think that you want to capture the ParticiapntID on the server side when you click on the gridview row
if i am correct then use the feature of datakeynames by setting it to participant id and then on the server side you can get the value back

set datakeyfield for gridview
<asp:GridView ID="grdview1" datakeynames="ID" ------>

while editing u can retrive id like this
string Id = grdview1.DataKeys[e.Row.RowIndex].Value.ToString();
0
 
LVL 2

Assisted Solution

by:phead_2
phead_2 earned 200 total points
ID: 24391850
PostBackUrl='<%# "~/SurveyData/evaluation.aspx?r=" + Eval("ParticapantID").ToString() %>'


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question