Solved

PostBackUrl with a ID attached to it

Posted on 2009-05-14
6
759 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
[X]
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
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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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