473,657 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get datagrid item text

Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with
CTYPE

however when the datagrid cell contains no control, but does contain text,
then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMembersh ips.Items
counter = counter + 1
If di.ItemType = ListItemType.Al ternatingItem Or di.ItemType =
ListItemType.It em Then
elem = doc.CreateEleme nt("Item")
elem.SetAttribu te("PKID", --WHAT GOES HERE TO RETRIEVE THE
TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribu te("membership" ,
CType(di.FindCo ntrol("Member") , CheckBox).Check ed)
elem.SetAttribu te("Accredited" ,
CType(di.FindCo ntrol("Accredit ed"), CheckBox).Check ed)
elem.SetAttribu te("membershipC ode",
CType(di.FindCo ntrol("Membersh ipCode"), TextBox).Text)
rootElem.Append Child(elem)
End If
Next
Nov 18 '05 #1
2 1582
martin wrote:
Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with
CTYPE

however when the datagrid cell contains no control, but does contain text,
then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMembersh ips.Items
counter = counter + 1
If di.ItemType = ListItemType.Al ternatingItem Or di.ItemType =
ListItemType.It em Then
elem = doc.CreateEleme nt("Item")
elem.SetAttribu te("PKID", --WHAT GOES HERE TO RETRIEVE THE
TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribu te("membership" ,
CType(di.FindCo ntrol("Member") , CheckBox).Check ed)
elem.SetAttribu te("Accredited" ,
CType(di.FindCo ntrol("Accredit ed"), CheckBox).Check ed)
elem.SetAttribu te("membershipC ode",
CType(di.FindCo ntrol("Membersh ipCode"), TextBox).Text)
rootElem.Append Child(elem)
End If
Next


di.Cells[0].Text would give you the text of the first column in the
grid, etc. Fill in the appropriate index.

BTW, if you were using a TemplateColumn for this 'text column', then you
could have used a LiteralControl in this column instead of plain text,
and you could then do something similar to what you do for the controls
(.FindControl.. .).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Thank you craig,

maybe you could tell me if it is possible to bind the changed datagrid
values back to a datatable in dataset (or the like) in a single
statement, ---just like a bind from the dataset to the datagrid in a single
statement, only the other way around.

what I am doing at the moments is iterating through my datagrid producing a
custon xml file that I am passing to the database, so that all updates can
be done in a single call to the db.

cheers

martin.
"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:eN******** ******@TK2MSFTN GP12.phx.gbl...
martin wrote:
Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with CTYPE

however when the datagrid cell contains no control, but does contain text, then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMembersh ips.Items
counter = counter + 1
If di.ItemType = ListItemType.Al ternatingItem Or di.ItemType = ListItemType.It em Then
elem = doc.CreateEleme nt("Item")
elem.SetAttribu te("PKID", --WHAT GOES HERE TO RETRIEVE THE TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribu te("membership" ,
CType(di.FindCo ntrol("Member") , CheckBox).Check ed)
elem.SetAttribu te("Accredited" ,
CType(di.FindCo ntrol("Accredit ed"), CheckBox).Check ed)
elem.SetAttribu te("membershipC ode",
CType(di.FindCo ntrol("Membersh ipCode"), TextBox).Text)
rootElem.Append Child(elem)
End If
Next


di.Cells[0].Text would give you the text of the first column in the
grid, etc. Fill in the appropriate index.

BTW, if you were using a TemplateColumn for this 'text column', then you
could have used a LiteralControl in this column instead of plain text,
and you could then do something similar to what you do for the controls
(.FindControl.. .).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3

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

Similar topics

3
3046
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is populated by the items in an arraylist shown in the code below. When the button is clicked I would also like the code to remove the items from the Arraylist. I've very little experience working with datagrids and arraylists so im finding this...
0
1651
by: shamila | last post by:
</asp:label><asp:datagrid id="DataGrid3" runat="server" cssclass="DataGrid" showfooter="True" onupdatecommand="DataGrid3_Update"ondeletecommand="DataGrid3_Delete" oneditcommand="DataGrid3_Edit" oncancelcommand="DataGrid3_Cancel" caption="Pricing Schedules" autogeneratecolumns="False" OnItemDataBound="ItemDataBoundEventHandler"> <alternatingitemstyle cssclass="DataGrid_AlternatingItemStyle" /> <columns> <asp:templatecolumn...
1
4312
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch the layout, some have child controls):
9
5053
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
4
3487
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
0
1827
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though it's a Sharepoint WebPart. I'm trying to do something fairly simple, create a datagrid that displays where and when a person works and allows them to change some of the information via DropDownLists. When the user clicks to edit a row, three of...
1
2358
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .. http://sf-f.org, weblog and search engine for fans and writers of
0
4015
by: Wyatt70 | last post by:
I'm attempting to implement a javascript popup calendar in a DataGrid. The calendar will be used to insert a date into a textbox. I keep getting a "System.NullReferenceException: Object reference not set to an instance of an object" error, which points to the following line: lnkCalendar.Attributes("OnClick") = String.Format("window.open('Calendar.aspx?textbox={0}','cal','...')", txtEstimatedDeploy) Here is the complete code for the...
9
2714
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
8
1253
by: brock wade | last post by:
I have a Datagrid that is working fine displying my records, but I'm trying to program buttons on each record line to launch another web page that shows all the details for the product: <asp:datagrid id="dgProducts" runat="server"> <asp:ButtonColumn Text="Details" CommandName="Details" ButtonType="PushButton"></asp:ButtonColumn> </asp:datagrid>
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system

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.