Get value of hidden gridview into session variable

 Hello and thanks for any ideas on this in advance.

I have a hidden casegridview from a sqldatasource with 2 values (case_id, client_id)

 The case gridview datasource takes a client id parameter from a second gridview, client

I'm trying to get the case_id into a session variable and can't figure out how to do it.

I tried using onselectindexchange for gridview2 but that didn't return anything because gridview2 doesn't have select enabled.

I have this code for my client gridview that gets a client id into a session variable:

 

protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack = True Then
            Dim i As Integer = GridView1.SelectedIndex
            
            
            'set  client id  from gridview into session variable
            Session("clientid") = GridView1.DataKeys(i).Value.ToString()
            Session("clientfname") = GridView1.Rows(i).Cells(2).Text.ToString()
            Session("clientlname") = GridView1.Rows(i).Cells(4).Text.ToString()
            
            '   (update client with the selected value from client gridview)
            DetailsView1.PageIndex = GridView1.SelectedIndex
        End If
        
    End Sub
Can I use this block to add a session variable for case id that is coming from gridview2? 
Any help is appreciated 
  
0
rothschildd
2/7/2008 10:55:32 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1006 Views

Similar Articles

[PageSpeed] 20

What events are you allowing in your first gridview, then?  You need some event to do this.  If update, insert, etc. use the code in your post in one of those event handlers to get the value from your second gridview.


Good Luck and happy programming!

Let's build community! If my post helped you, mark it as the Answer and I will do the same
when you help me...this will help everybody!
0
dtrent
2/9/2008 6:33:38 PM

set the datakeynames property of the gridview to case_id then on the selectedindexchanged event write

Session("case_id")=YourGridview.SelectedValue 

0
s10n
2/9/2008 7:28:06 PM

 Hi and thanks for the reply,

I tried using GridView2_SelectedIndexChanged , but that didn't return anything. I think it's because nothing in gridview 2 is selected, instead it changes according to the row selected in gridview1.

Here is the code that I tried:

Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'set  caseid  from gridview into session variable
        Dim caseid
        Session("case_id") = GridView2.SelectedValue
        caseid = Session("case_id")
        Label3.Text = Session("case_id")
    End Sub

  I used a label to test what case_id is returned. Is there a different event I should try?

Thanks for the advice. 

0
rothschildd
2/15/2008 3:21:35 PM
Reply:

Similar Artilces:

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Get Value from Hidden Column in Gridview control
I have managed to get the value from my hidden field by using the SelectedIndexChanged event and the following line of code:string keyValue = GridView1.SelectedDataKey.Value.ToString()I would however prefer to get access to the hidden column value on the GridView1_RowDataBound event, so that I can then evaluate each row against the hidden columns value and decide whether or not to display the edit button in each row. Can I do this a different way? You can use e.Row.DataItem("field name") in the RowDataBound event -  as long as the field is in your SQL statement doesn't m...

GridView child of GridView
I have a Parent GridView and when you click in the Edit one of the columns has a Template Field which has a Child GridView. When you click Edit on the Child GridView I have a Template Field that has a TextBox. How to I retreive this value of the TextBox? GridViewParent-- GridViewChild (Edit - Template Field containing this GridViewChild)----- TextBox inside Template Field in GridViewChild. Thank you.Peace in ChristMarco Napolihttp://www.ourlovingmother.org What you can do as a solution is to override the RowDataBound and try to find the child GridView control. Once you get a reference to...

How to get session variable value into a static variable
Hi, On page preinit i am adding few session variables. Now i want to retrive these session variable values into my static variables. protected void Page_PreInit(object sender, EventArgs e) {Session.Add("T", "Default"); Session.Add("T1", "Red"); Session.Add("T2", "Blue");   }   i have few static variables which shud contain these vaules.  public string TT; public string TT1; public string TextForeColor =sess = "#FFFFFF";   i want to get T value into TT ... T1 into TT1..and so on &n...

How to get the value hidden control of user control in .aspx page
How to get the value hidden control of user control in .aspx page   Thanks srinivas  If its a server control (runat attribute = server) and its markup starts with <asp:HiddenField ID="HiddenField1">, you can just call HiddenField1.Value to get the value stored in it. Even if your hidden field is not a standard asp.net control you can still retrieve the value provided the runat attribute is set to server.Hope this helps programming blog Use <%=testhid.ClientId%>For example getting a reference to the object would look like:var testid = document...

Issue with getting values from child controls in a gridview, to use for the update using a SQLDataSource control
Hi all, I have a gridview bound with a SQLDataSource. I am using the Update feature of the SQLDataSource to update a SQL Server database with values entered into the gridview. However I am not getting it to work. I believe this is due to the controls that contain the user entries are not the gridview itself, but rather child controls within the gridview. I have been using the names of the actual controls but nothing happens. Upon submit, the screen returns blank, and the database is not updated. Here is some code:   <asp:GridView ID="GridEditSettlement" runat="server" AutoGenerate...

Getting value out of session variable
 Hi,How to get the value of a session. It is storing the dataset value. I dont know how to transfer that to a variable.   private SearchDotnet.Searchs.UserSearch sSite;  if ((sSite == null))          {             sSite = Session["Site"];           }         }  The thing is sSite is  delcared as above. I need to unload the session variable to sSite. Have not found a...

Session Variables (Get values)
Hi, I am storing some variables in Session, Double values, Integers and Strings.Sometimes these values can be null or empty (""). While retrieving these values from session I will declare a variable of its type. Let say for example I want to get a Double value from Session. Dim dblAmount as DoubledblAmount = Session("sessAmount") Here I am getting trouble when value is empty, its giving an errorConversion from string "" to type 'Double' is not valid. How to handle this kind of situations? Let me know your suggestion. Thanks   Hi. Before assigning the value, check if the session...

getting value of session variable
I'm trying to display the value of a session variable in a label. I know the session variable exists because in my page load event I redirect the user to a different page if it's value is null. I want to display it's value in a label to test some things, but I keep getting an error whenever I try.  Here is my code:   Label:<asp:Label ID="lblSessionTest" runat="server" Text="Label"></asp:Label>  How I'm trying to display it (in my page load event):  lblSessionTest.Text = Session("loggedIn"); &nbs...

How can I display a session value in a textbox on the next page or/and use this session variable in my where clause of a datasource control?
How can I displacy a session value in a textbox on the next page or/and use this session variable in my where clause of a datasource control?  Can someone tell me how I can display a session variable from one page to the other page's control?  I am wrinting a session value using this on my default.aspx page :  Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.ClickSession("myKey") = 1 Response.Redirect("page1.aspx") End Sub on page1.aspx: <asp:View ID="view1" runat="ser...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Session variable value gets lost
I am using asp.net 3.0 with C#. My web application requires some values that is used across my User Controls. These values are pertaining to the login user name and User type. When each user is logged in I store that username and user type in a session variable and whenever i need to used it like in a query I just called the string variable that is assigned to the Session variable. My problem is sometimes my session object/ string variable loses its value and I am wondering is there another way of storing my User's credential so that the value will not be lost until the User closes his/h...

Getting Value of Hidden field in GridView??
I have read a gazillion walkthroughs on this but none of them seem to work for me?? I have the label below that is storing the primary key from a sql db:<asp:TemplateField Visible="false"> <ItemTemplate><asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' /> </ItemTemplate> </asp:TemplateField> Can someone please show me how to access this value using c#? I can use the code below to access any of the values that are being displayed but I cannot access the hidden label?int index = Convert.To...

Not getting values in hidden fields in a Gridview
Here's the gridview:   <asp:GridView id="gvGenerateSchedule" runat="server" Width="500px" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" DataKeyNames="squadDetailID" Font-Size="Smaller" Font-Names="verdana" SelectedRowStyle-Font-Size="Smaller" SelectedRowStyle-Font-Names="verdana" HeaderStyle-Font-Size="Small" EditRowStyle-Font-Size="Smaller" EditRowStyle-Font-Names="verdana"...

Web resources about - Get value of hidden gridview into session variable - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/9/2016 8:54:11 AM