Solved

How do i  insert a session variable into gridview

Posted on 2008-10-14
6
860 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
  • 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 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now