473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to retrieve cell value from grid view using button column in c#

I am using grid view and a button column in it using <itemTemplate>
but I am not able to rerive cell value of a selected row from grid view.
I have tried the following to methods in Row_command event of gridview but it gives Null reference exception error while clicking the button in button column of grid view :
Expand|Select|Wrap|Line Numbers
  1.  int index = gdvOdetails.SelectedIndex;
  2.         object oid = (object)gdvOdetails.SelectedDataKey.Values["o_id"];
  3.         txtMsg.Text = oid.ToString();
  4.  
  5.  for (int i = 0; i < gdvOdetails .Rows .Count ; i++)
  6.             {
  7.                 if (gdvOdetails.SelectedIndex == i)
  8.                 {
  9.                     txtMsg .Text  =gdvOdetails.Rows[i].Cells[1].Text; 
  10.                 }
  11.             }
  12.  
can any one help to retrieve cell value of grid in any variable using button column
Feb 5 '08 #1
2 7552
Frinavale
9,735 Expert Mod 8TB
I am using grid view and a button column in it using <itemTemplate>
but I am not able to rerive cell value of a selected row from grid view.
I have tried the following to methods in Row_command event of gridview but it gives Null reference exception error while clicking the button in button column of grid view :
Expand|Select|Wrap|Line Numbers
  1.  int index = gdvOdetails.SelectedIndex;
  2.         object oid = (object)gdvOdetails.SelectedDataKey.Values["o_id"];
  3.         txtMsg.Text = oid.ToString();
  4.  
  5.  for (int i = 0; i < gdvOdetails .Rows .Count ; i++)
  6.             {
  7.                 if (gdvOdetails.SelectedIndex == i)
  8.                 {
  9.                     txtMsg .Text  =gdvOdetails.Rows[i].Cells[1].Text; 
  10.                 }
  11.             }
  12.  
can any one help to retrieve cell value of grid in any variable using button column
Unless your button is a Select button, your gdvOdetails.SelectedIndex will be nothing (because no row is selected). Try using a "select" button instead of a command button in your GridView.

-Frinny
Feb 5 '08 #2
Plater
7,872 Expert 4TB
If the button they clicked is IN the row that you want, you can get the row/column indexes from the event.
Feb 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: James | last post by:
wxpython 2.5.3 hi, anyone know how to make a multiline cell editor for wxgrid? thank you :) best regards, James
4
by: Clara | last post by:
Hi, can somebody help me,..I have an assignment due next week but now I'm stuck with this problem.... I tried to get values from entry widget using the widgetcontrolvariable.get(),..but it seems...
1
by: dsoltesz | last post by:
I have a grid that has a couple columns all are bound columns except one..which is a button column. I use the code TableCell IDColumn = e.Item.Cells; FileName = IDColumn.Text; if I set...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
3
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
3
by: Henry Jones | last post by:
I am using VB.NET VS 2005 and I have a datagridview bound to a table. This table has rate information on bank loans. The fiels are ProductName, MinDeposit, Rate, and PreviousRate On the grid...
0
by: anuparvathy | last post by:
Hi I am creating a website using visual studio 2005. In the design view of my asp.net page i have placed a grid view and then i have connected it to the database also. i have set the item style...
6
TMS
by: TMS | last post by:
This spreadsheet is almost done, but there is some functionality that is driving me nuts. For instance: a cell, for instance 'a0' is to have 'a0' as a string, but if something is entered like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.