How can I get data value from datasource

I Have extracted data from an access database created a datagrid which works great. In the data grid I am only using part of the columns extracted from the data base. The dataTarps_Commands sub is executed when a link button is clicked in the datagrid. I am able to retive item data that is displayed using bound columns in the data grid  but I have not been able get cell information for columns not displayed or displayed using template columns. 

Is there a way to get information from the data source in a function. Ideally I would like to address these cells using the header name and current row.

<%@ Page Language="VB" Debug="True" %>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)

If Not Page.IsPostBack then
labelPost.text = "Nothing has been selected yet."
End If
End Sub

Sub BindTarpsGrid()

dgTarps.DataSource = GetTarps("Clear Tarp")

End Sub

Function GetTarps(ByVal name As String) As System.Data.IDataReader
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT [tblTarps].* FROM [tblTarps], [tblTarpsDescriptions] WHERE (([tblTarps].[N"& _
"ame] = [tblTarpsDescriptions].[Name]) AND ([tblTarps].[Name] = @Name) AND ([tblT"& _
"arps].[LWOrder] <> ""R"")) Order By SKU"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_name As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_name.ParameterName = "@Name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String

Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function' Insert page code here

Sub dgTarps_Command(sender As Object, e As DataGridCommandEventArgs)

Select (CType(e.CommandSource, LinkButton)).CommandName

Case "Post"

labelPost.Text = "Posted Data: " & "- Grommets " & convert.ToString(e.Item.Cells(2).Text)
labelPost.Text += "<br>Price: " & Cstr(Csng(convert.ToString(e.Item.Cells(3).Text)))
labelPost.Text += "<br>Description: " & convert.ToString(e.Item.Cells(1).Text)

Case Else
' Do nothing.
End Select
End Sub
<form runat="server">
<asp:DataGrid id="dgTarps" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="12pt" CellPadding="3" BorderWidth="2px" BorderColor="Black" AutoGenerateColumns="False" onItemCommand="dgTarps_Command">
<AlternatingItemStyle backcolor="Silver"></AlternatingItemStyle>
<HeaderStyle horizontalalign="Center" backcolor="#6666CC"></HeaderStyle>
<asp:BoundColumn DataField="Size" HeaderText="Size"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Description">
<asp:Label id="LabelName" runat="server" text='<%# DataBinder.Eval(Container.DataItem,"Description" ) %>' ></asp:Label>
<asp:HyperLink id="HyperLink1" Text="<br>Click for canopy and tarp accessories" NavigateUrl="" runat="server" />
<asp:BoundColumn Visible="False" DataField="Ties" HeaderText="Grommets"></asp:BoundColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn DataField="ShipWt" HeaderText="Ship Wt"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Order">
<p id="" >
<asp:LinkButton id="lablePostit" CommandName="Post" runat="server">Post</asp:LinkButton>
<!-- Insert content here -->
<p id="">
<asp:Label id="labelPost" runat="server"></asp:Label>

2/13/2005 7:38:17 AM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 11


first of all I want to recommend the following link cause this article describe in detail using the FindControl method of a datagrid item... In search of ASP.Net controls.
In your code example you have to use this method for getting cell information of a template column regardless if in a datalist or in a datagrid. For example to get the content of the description field in the ItemCommand-event for the selected row you should use the following code:
Dim Description as string

Description = CType(e.Item.FindControl("LabelName"), Label).Text
2/13/2005 6:10:00 PM
This works great and the article you referenced was very good background information. 

Thank you,
2/14/2005 2:28:29 AM

Similar Artilces:

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Getting Information from the Controls (TemplateField or BoundField ) from any of the Data Presentation Controls
Hello Everybody,I have a very important question for me.For example, I have a GridView.It has three BoundFields and one TemplateFieldI want to get information from any of the record (row,line etc ) using any of the BoundFields or TemplateFields.And also I want to accomplish this not only with GridView but also other Data Presentation Controls, DetailsView FormView and Repeater.Shortly, Can anybody help me how to refer Controls in GridView, FormView, DetailsView, RepeaterPS: I have searched in Google and many sites,forums. But I couldn't see any solution and see that many people ask the same ...

1 Data Control, 2 datasources?
ok - I am fairly new to the .Net way of doing things - so maybe the answer to my question is staring me in the face, but I need some help to see it!  Thanks in advance for any who read this! :)  I have a form with a DataList on it.  in the Item template, I have many data controls. (CheckBoxList, DropDownList, etc.)  I have set the Datasource of the DataList to an ObjectDataSource (odsDetails) - and for fields that I can bind directly to controls (textboxes, etc) - this works great! However, I have other queries that populate the items in the dropdownlist and the...

FileUpload control value gets clear when another control uses Ajax to retrieve data
Hello all, I have a web form.  There is a DropDownList control inside an update panel and the content is updated when a RadioButtonList control fires SelecteIndexChanged.  I also have another control, a FileUpload control.  If you select a file for the file upload control and then change the value RadionButtonList list control, the selected file in the FileUpload control disappears.How do I prevent RadioButtonList from clearing the value of the FileUpload control?Any help will greatly appreciated,  TIA,Dawa Below is the code: 1 <asp:RadioButtonList ID=&quo...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

how can i get the values in checklist control?
i have a checkboxlist control with values inside like five values. i want to check multiple values and band it to a label. pls how is it possible? string str = "";foreach(ListItem li in CheckBox1.Items){    if (li.Selected)        str += li.Value + "<br />";}Label1.Text = str;You can use to convert to VB is required.  Regards Mike [MVP - ASP/ASP.NET]My site...

How can I get the value from a Data Grid?
How can I get the text out of a datagrid? I have a help desk application that once the ticket is closed, it will fire off an email to the person that submitted it. That persons email is displayed in a datagrid. I need that info to use it in the email address. Any hints???? dim userEmail as string userEmail = CType(e.Item.FindControl("Email"), TextBox).Text...

login control can i used to controll what data can user see it
i have a project with mulit company can i used login control to control what company user can see it and what user cant see it the company comes from databasethanks alot for any help first of all you should have a table in database database that contains (user_id, company_id,  password, auth_level). the auth_level can be used to grant specific content/page access to each user of each company. but, you need to override the authentication process as bellow.    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { L...

I can SEE the data, but I can't GET the data...which is the most important to me :/
I've got a linkbutton I click, which (in an update panel) posts back, queries a database for values, then searches the controls in another updatepanel and updates their Text fields with that data....that part works great. I then have a master button (not in an update panel) which is supposed to query those same controls, and concatinate the Text values.  This is the part which doesnt work when I click the LinkButton...however if I just manually enter the values then click the master, I get all my text. Any idea what might be going on? :( Look for JavaScript errors in your browse...

2nd Data Grid Control
Hi, i have a DataGrid control on page that has a hyperlinked field.  When you click on the hyperlink the page opens, and returns the selected information from the database as it is supposed to.  However, I wanted to put another dataGrid on the hyperlinked page that pulls up more information about the hyperlinked item.  I tried this SQL statement but it returns all the rows of the database, when in actuality all i want it the second dataGrid to show certain columns from a different DB table.   SELECT     tbllog.IttNumber, tbllog.IttLog, tbllog.Lo...

Can a DataSource set the default value in a DropDownList (or the list fetch the value from a DataSource)?
Hi I have a DropDownList that gets its values from a DataSource-control. Nothing magic so far. What makes me scratch my head is that I need to set the default (selected) value in the drop down. As the values come from a data source, I do not know the key/value/index of the default I. Is there a possibility to make the drop down "ask the data source" which key should be the default (that is, only if the drop down is populated the first time, of course)? Background: I have an application where an administrator can set the "standard" month that the application s...

How can I get the value of a control inside PlaceHolder
How can I get the value of a control inside PlaceHolder with c# Depends where the PlaceHolder is living (if it's inside a template of a DataList or Repeater) and whether it was filled with a control at compile-time (likely the case) or at runtime. The basic approach is this: Lable lbl = (Label) thePlaceHolder.FindControl("theIdOfTheControl"); string whatINeed = lbl.Text; Of course you can do the same with a TextBox control or so (replace the castings, replace the name of the control in the FindControl call and use the property you need to retrieve the information you ...

How can I get other column value of DataSource in ItemDataBound event?
Hi all In ItemDataBound event, How can I get other column value of DataSource? for example ,I have 3 column,customer_id,customer_name,customer_tel customer_id,customer_name has display on DataGrid. Now I want to get customer_tel in ItemDatabound event. How do I? Thanks a lot. Clare There is a DataItem property of the e.Item that ruturns items datasource. All you need to do is to cast it to an appropriate type. If you binding your grid to DataTable or DataView, it is DataRowView Dim dtr as DataRowView = ctype(e.Item.DataItem,DataRowView) Bug [MCSD]...

Web resources about - How can I get data value from datasource -

Datasource - Wikipedia, the free encyclopedia
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property ...

Inverness Graham Acquires DataSource
Inverness Graham , a lower middle market private equity firm headquartered in suburban Philadelphia, has acquired DataSource , a print supply ...

SmartGlance for iPad for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about SmartGlance for iPad on the App Store. Download SmartGlance for iPad ...

Chaitanya Pandit (@chaitanyapandit) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Data source - Wikipedia, the free encyclopedia
... Data source A data source is any of the following types of sources for (mostly) digitized data: a database in the Java software platform, datasource ...

2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Tagged entries for CLOUD COMPUTING
Alan Williamson's output as a Java Champion, Blog-City Architect, BlueDragon Creator, Author, Speaker and Internet Guru

Private equity deals
... of biometric identity management systems, applications and services. Inverness Graham Investment has acquired DataSource ...

C# C Sharp and Tutorials on C#
Learn the c# langauge to build web applications using our online tutorials with live demos. Participate in our forums and learn from others. ...

JavaScript UI Library, Ajax Components & HTML5 Framework - DHTMLX
DHTMLX offers a rich JavaScript library, UI components & HTML5 mobile framework. Build impressive web apps for both desktop and mobile devices. ...

Resources last updated: 11/28/2015 1:08:30 AM