Cross Page Postback and Datagrid.

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

On a Datagrid defined as
<asp:datagrid id="dgCountries" width="100%" AutoGenerateColumns="False"
Runat="server" CellSpacing="1" BorderWidth="0px" CellPadding="2"
DataKeyField="code">
<Columns>
<asp:BoundColumn DataField="Code"
HeaderText="Code"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.Code",
"somepage.aspx?countryid={0}") %>'>
<img id="StateImage" runat="server"
src="~/APP_Themes/buttons/Regions.gif" border=0 />
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

the hyperlink provides the row clicked via the Query string. We are getting
rid of the querry string and I need to implement this via CrossPagePostback.
So far I can not figure out how to access which row was selected before it
was passed on the querystring. I am able to access the grid but from there I
am stuck.

the hyperlink above will be changed to something like
<asp:Button Runat=server PostbackUrl="somepage" Id="somecontrol">

Any help would be really appreciated.
 
if i understand your problem
you could use a hidden field a javascript function that is called
when you click the hyperlink to set the value of the hidden field with the
value you want

something like

javascript

function setValue(value)
{
var hidden = document.getElementById('<%=hiddenField1.ClientId%>');
hidden.value = value;
}

code-behind
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

Button bt = (Button)e.Row.FindControl("button1");

bt.Attributes.Add("onclick", "setValue(' " + e.Row.RowIndex (or any
value you want to persist + "')");


}

}
 
Thank you for your input.

Is there a simply way to be doing this. I am new to the CrossPagePostback
and want to make sure I am not overlooking something
 
well i normally dont use CrossPagePostback ...but that's me :)
i perfer to user userControls and control myself the data using viewstate
my idea is that full postback of one page on another is something to avoid

sorry my bad english
 
Back
Top