?
Solved

How do i  insert a session variable into gridview

Posted on 2008-10-14
6
Medium Priority
?
869 Views
Last Modified: 2012-05-05
Hello,

I am using ASP.NET and VB.NET, I have a gridview wconnected to a table adapter which returns 3 columns from a database. Column 1 is a feature ID, column 2 is a description and column 3 is detail.

Can I in some way insert a Session variable into a cell in Column 3 where ID = 3 for example.

thanks, much appreciated.
0
Comment
Question by:pythonV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22718667
Hi,

You can interfere anytime in anyway your gridview bind its data, and manipulate the way you want it.

Set the event RowDataBound of your gridview (this event will be fired when datarow is bounded, your can set how you want the specific cell to display. You use VB right? So please take a look at the example:

<asp:gridview id = "myGridView" runat = "server" onRowDataBound = "..." ... > (you better get this on your design)

For more information please visit
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx

Hope this helps
JINN

Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
 
    If e.Row.RowType = DataControlRowType.DataRow Then
 
      ' Get your session variable and display here.
      e.Row.Cells(2).Text = "<i>" & Session("MySessionValue") & "</i>"
 
    End If
 
  End Sub

Open in new window

0
 

Author Comment

by:pythonV
ID: 22719077
thanks for the response,however, what this is doing is filling all the cells in the column with the same variable. I want just 1 specific cell.

thanks.
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 2000 total points
ID: 22719105
Put one more if statement in, to check the row index (to see if the row match your condition then change it).This wont slow down the performance (very very little effect).

If e.Row.RowType = DataControlRowType.DataRow Then
      if e.Row.Cell(0).Text = "3" then    'or equals your wanted ID
         ' Get your session variable and display here.
         e.Row.Cells(2).Text = "<i>" & Session("MySessionValue") & "</i>"
      End if
 
    End If

Hope this help
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:pythonV
ID: 22719128
Thank you, Problem Solved!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22719131
If you want to insert that value after the grid has been populated then you need to update the datatable which is the source of the grid. If you are using dataset or datatable to populate the grid, you could insert the value into table and then refresh the grid. For example

dTable.DefaultView.RowFilter="FeatureID=3"
if dTable.DefaultView.Count>0 then
   dTable.DefaultView.Item(0).Item(2)="SomeValue"
end if
dTable.DefaultView.RowFilter=""
dGrid.DataBind()
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22719139
Glad to help ^^

JINN
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

801 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