How to get data from the row selected in a gridview with radiobutton onclicked event?
I've a gridview in which a radiobutton is used to select a particular row of data. The radiobutton onclick event is done through Javascript.
Now I need to save the data in this selected row into some session value so that I can use in another pa开发者_如何转开发ge. How do I achieve this?
I'm not using JQuery or Ajax, my entire coding is done on ASP.NET 3.5
Session ( 'VariableHere' ) = 'Data';
// display variable anywhere on your site
Out ( 'Your variable is ' + Session ( 'VariableHere' ) );
i don't understand why you would need it in session, the session is per user, you could use Application variables as I don't think you need it per session.
The blog post HERE has the code for this:
Add data keys to your GridView:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ItemID" ... >
Add a value to your radio button (intellisense doesn't support it, but it's there):
<asp:RadioButton ID="RadioButton1" runat="server" onclick="radioClick(this);" Value='<%#Container.ItemIndex%>' />
In your JavaScript method:
radioClick = function(radioCtrl){
__doPostBack("<%=GridView1.UniqueID%>", radioCtrl.value);
}
And add the RaisePostBackEvent method to your code behind:
protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
{
//call the RaisePostBack event
base.RaisePostBackEvent(source, eventArgument);
if (source is GridView)
{
if (source == GridView1)
{
int itemID = (int)GridView1.DataKeys[Int32.Parse(eventArgument)]["ItemID"];
}
}
}
精彩评论