473,396 Members | 1,987 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.

Getting value from cell in datagrid

I ahve a datagrid on a web form. I need to change the value in column 3 as
follows.

If the value in column 3 reads 0, I want to change it to read YES.

How can I accomplish this task.

Thanks,

Dave
Nov 16 '05 #1
4 3458
If you filled the datagrid from a dataset, just iterate through your dataset, change the values:

for (int i=0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j=0; j < ds.Tables[0].Columns.Count ; j++)
{
if(ds.Tables[0].Rows[i][j].ToString() == "0")
ds.Tables[0].Rows[i][j] = "YES";
}
}
The datagrid to will to be updated with the new data.

k-lo
I ahve a datagrid on a web form. I need to change the value in column 3 as
follows.
If the value in column 3 reads 0, I want to change it to read YES.
How can I accomplish this task.
Thanks,
Dave


User submitted from AEWNET (http://www.aewnet.com/)
Nov 16 '05 #2
subscribe to the DataBound event on the datagrid and subsititute the value
as required

e.g.

private void XXXX_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item) ||
(e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.Alternating Item))
{
if(XXXX.Items[e.Item.ItemIndex].Cells[2].Text == "0")
XXXX.Items[e.Item.ItemIndex].Cells[2].Text = "YES";
}
}

HTH

Ollie Riches

"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
I ahve a datagrid on a web form. I need to change the value in column 3 as follows.

If the value in column 3 reads 0, I want to change it to read YES.

How can I accomplish this task.

Thanks,

Dave

Nov 16 '05 #3
I now get the following error:

Server Error in '/DataViewer' Application
--------------------------------------------------------------------------------

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:
Line 199: (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.Alternating Item))
Line 200: {
Line
201: if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text ==
"0")
Line
202: applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text =
"NO";
Line 203: }
Source File: c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs Line:
201

Stack Trace:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataGridItemCollection.g et_Item(Int32 index)
DataViewer.permissionForm.applicationPermissionGri d_ItemDataBound(Object
sender, DataGridItemEventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:201
System.Web.UI.WebControls.DataGrid.OnItemDataBound (DataGridItemEventArgs e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
DataViewer.permissionForm.FillApplicationPermissio nGrid() in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:169
DataViewer.permissionForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573

What am I doing worng here? The code is as you sent to me.

"Ollie Riches" wrote:
subscribe to the DataBound event on the datagrid and subsititute the value
as required

e.g.

private void XXXX_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item) ||
(e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.Alternating Item))
{
if(XXXX.Items[e.Item.ItemIndex].Cells[2].Text == "0")
XXXX.Items[e.Item.ItemIndex].Cells[2].Text = "YES";
}
}

HTH

Ollie Riches

"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
I ahve a datagrid on a web form. I need to change the value in column 3

as
follows.

If the value in column 3 reads 0, I want to change it to read YES.

How can I accomplish this task.

Thanks,

Dave


Nov 16 '05 #4
don't forget that collections in .Net start at index zero, so if you want
item six it would XXXXX[5]

HTH

Ollie Riches

"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
I now get the following error:

Server Error in '/DataViewer' Application.
-------------------------------------------------------------------------- ------
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:
Line 199: (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.Alternating Item))
Line 200: {
Line
201: if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text ==
"0")
Line
202: applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text =
"NO";
Line 203: }
Source File: c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs Line:
201

Stack Trace:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataGridItemCollection.g et_Item(Int32 index)
DataViewer.permissionForm.applicationPermissionGri d_ItemDataBound(Object sender, DataGridItemEventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:201
System.Web.UI.WebControls.DataGrid.OnItemDataBound (DataGridItemEventArgs e) System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
DataViewer.permissionForm.FillApplicationPermissio nGrid() in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:169
DataViewer.permissionForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx. cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


-------------------------------------------------------------------------- ------ Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

What am I doing worng here? The code is as you sent to me.

"Ollie Riches" wrote:
subscribe to the DataBound event on the datagrid and subsititute the value as required

e.g.

private void XXXX_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item) || (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.Alternating Item))
{
if(XXXX.Items[e.Item.ItemIndex].Cells[2].Text == "0")
XXXX.Items[e.Item.ItemIndex].Cells[2].Text = "YES";
}
}

HTH

Ollie Riches

"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
I ahve a datagrid on a web form. I need to change the value in column
3 as
follows.

If the value in column 3 reads 0, I want to change it to read YES.

How can I accomplish this task.

Thanks,

Dave


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CDWaddell | last post by:
I have the following cod private void btnUpdate_Click(object sender, System.EventArgs e TextBox tbMembers = new TextBox() tbMembers = (TextBox) dlClubs.FindControl("tbMembers") string...
5
by: velu | last post by:
Problem in getting value from textbox & radiobuttonlist to a valuable inside a datagid. I want to insert a record into a table thru datagrid. Here is the code (see below) Private Sub...
2
by: niceguy | last post by:
Hi I was wondering if its possible to get the exact displayed text from a cell in a datagrid. I need to get the displayed text and not any 'real' database value or anything that the cell...
4
by: gugu | last post by:
Hi I have a datagrid which has 20 rows and 20 columns, 15 of 20 columns are checkboxs and their headertexts, datafields are dynamic. I need to loop through the whole page to see if the specific...
1
by: sathyan8294 | last post by:
what is vb.net code for search the value in datagrid by select the value in combo box using vb.net windows application.
1
by: darla0520 | last post by:
Hi, Please anyone help me, I have a datagrid on my child window wherein I have to return the value of the datagrid on the parent window when I click the link button. Or do you have any sample code...
1
by: renatois | last post by:
Getting value from GridView Hi guys, I have a GridView and I need to access a value of an ID field on an event. I converted this field into template and the name of the label control in...
2
by: HenrikRinder | last post by:
This is a silly question, but now I have spent hours trying to figure it out. Thus, asking this forum: Our application GUI has a .NET PropertyGrid. Our customers don't find it intuitive to...
6
by: Sep410 | last post by:
Hi, How can I access the selected row value in datagrid in vb.net?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.