On Apr 2, 4:31 pm, "jobs" <j...@webdos.comwrote:
I have a gridview on another page with a column that will link to this
page. I'm flirting with design options, but am considering a template
field with hyperlink navigateurl that includes a query string ?
search=mydata container.
My question/challenge, is that I want to use that query string to set
a textbox on the called page, but then need the query string to no
longer be visible in the url espectially after a refersh or other
selection. I guess I could use response.redirect to clear the query
string, but won't that cause my textbox viewstate to be cleared
defeating the whole exercise.
None of this would be a problem, If I could somehow link a gridview
column to a subroutine where I set a session variable and call the
destination search page. A session variable would be easy to remove
after using it. In this scinereo, how can I like data in a gridview to
a row command or codebehind subrutine on the same page?
Thanks for any help or information!
You can try using the SelectedIndexChanged event. In the example
below when the LinkButton is clicked the event will be fired and do a
Server.Transfer to another page. This second page can get the
selected record's unique id. This way you won't pass anything in the
url.
-------
Page1
private int _selectedUID;
public int SelectedUID
{
get { return _selectedUID; }
set { _selectedUID = value; }
}
protected void gvSearchResults_SelectedIndexChanged(object sender,
EventArgs e)
{
SelectedUID = (int)gvSearchResults.SelectedValue;
Server.Transfer("Page2.aspx", true);
}
-------
<asp:GridView ID="gvSearchResults" runat="server"
AutoGenerateColumns="false" AutoGenerateSelectButton="false"
GridLines="none" DataKeyNames="uid" SelectedIndex="0"
OnRowDataBound="gvSearchResults_OnRowDataBound"
OnSelectedIndexChanged="gvSearchResults_SelectedIn dexChanged" Font-
Size="x-Small" CellSpacing="1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDetail" runat="server"
CommandName="Select" Text="View Detail" ForeColor="darkBlue" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
--------------------
Page2
int UID = this.PreviousPage.SelectedUID;
-----
<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>