Solved

PostBackUrl with a ID attached to it

Posted on 2009-05-14
6
742 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now