473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get values from Cells in a GridView

2 New Member
Hi All.

I am using a GridView to List contacts linked to a logged in User.

I can successfully bind the Gridview with a DataTable. And the values in the GridView are correctly displayed.

I have a BoundField at Index 0 of the GridView which pulls a value from a Column in the DataSource (datatable).

The problem I am facing is that all the values in the cells are coming back as empty strings.

Can Anyone help me understand what I am leaving out and what I am doing wrong.

Code is as below:
Expand|Select|Wrap|Line Numbers
  1. protected void grdContactList_RowCommand(Object sender, GridViewCommandEventArgs e)
  2.     {
  3.         Global.BindGridView(ref grdContactList, Global.g_dtContacts);
  4.  
  5.         if (e.CommandName == "EditContact")
  6.         {
  7.             string strCmdArg = Convert.ToString(e.CommandArgument);           
  8.             string strContactID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[0].Text;           
  9.             Server.Transfer("EditContact.aspx?contactid=" + strContactID);
  10.         }
  11.         else if (e.CommandName == "DeleteContact")
  12.         {
  13.             string strCmdArg = Convert.ToString(e.CommandArgument);
  14.             string strContactID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[0].Text;
  15.             string strAgentID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[1].Text;
  16.             Contact.DeleteContact(strContactID, strAgentID);
  17.         }
  18.     }
  19.  
  20. The values of both strContactID and strAgentID are coming back as "".
  21.  
  22. BindGridView(...) is basically...
  23.  
  24. GridView.Datasource = dtDatatable;
  25. GridView.Databind();
  26.  
Thanks.
Nov 12 '07 #1
2 1268
Plater
7,872 Recognized Expert Expert
Are you sure you should be re-binding before each click?

Also, you're looking at the first two columns, would those first two columns not be you buttons? Is it possible you're not looking at the columns you thought you were?
I've taken to doing a "dynamic" search.
Expand|Select|Wrap|Line Numbers
  1. int theRowIDX = 0;
  2. int.TryParse(e.CommandArgument.ToString(), out theRowIDX );
  3. int WantedIDX=-1;
  4. for (int i = 0; i < gvIssuesSites.HeaderRow.Cells.Count; i++)
  5. {
  6.    if (gvIssuesSites.HeaderRow.Cells[i].Text == "MyWantedColumnName")
  7.    {
  8.       WantedIDX= i;
  9.    }
  10. }
  11. if (WantedIDX != -1)
  12. {//it found the column I wanted
  13.    string mytext=gvIssuesSites.Rows[theRowIDX].Cells[WantedIDX].Text
  14. }
  15.  
Nov 12 '07 #2
mzmishra
390 Recognized Expert Contributor
addition to that you can also do like below
private void grdContactList_ItemCommand(object source, DataGridCommandEventArgs commandEventArgs_)
{


DataGridItem item = commandEventArgs_.Item;




int strContactID=int.Parse(item.Cells[0].Text);
Server.Transfer("EditContact.aspx?contactid=" + strContactID);


}
Nov 13 '07 #3

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

Similar topics

5
25292
by: maurban | last post by:
Hi there experts, I have a gridview with a couple textboxes and a dropdownlist. I'm trying to insert a default value into my database driven dropdownlist. I'm doing this in the rowdatabound...
1
1046
by: =?Utf-8?B?QmVydA==?= | last post by:
HI I am trying to get the values from my gridview to process them in another function. I tried gridview.rows(0).cells(0).tostring()? thanks B
1
12178
by: mark4asp | last post by:
I have two grid views on the page and I want them to share the same RowDataBound event. In debug mode in notice that sender and gvMandates (below) are both termed...
0
1190
by: Pemmavasu | last post by:
Hi All, I am not able to read the values from Gridview TemplateField Controls. basically I craeted a gridview with four colums and finally i added a Template field to it. The templatefield...
1
5746
by: Kevin S Gallagher | last post by:
I am looking for advice/code to assist in determining which cells are visible on a DGV. The code below works but wanted to see if there are better methods or perhaps the code below has issues I...
7
12943
by: rote | last post by:
I would like to make my Gridview header dynmic i.e databinded from database.. I want my users to be able to change the headers on the fly.. Any ideas?
2
3333
by: bogdan | last post by:
Is it possible to have a CompareValidator to compare values from two cells in a gridview row? I'd like to do that while in edit mode. Thanks, Bogdan
1
1968
by: Ben | last post by:
Hi, The gridview contains a radiobuttonlist with boolean values (true/false) coming from a database. In normal mode, the gridview displays True or False for that field. What i want is to...
3
1014
by: kimbred | last post by:
Can someone help me? Using the following code, I should get the values in the cells of the selected row of my gridview. When I get the value of the cells, their empty. protected void...
0
7224
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
7120
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
7380
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...
1
7039
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
7494
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
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.