How do you get a column value from a gridview column

How do you get a column value from a gridview column in asp.net 3.5?

I tried this but it does not work.

Dim myRow As GridViewRow
For Each myRow In GridView1.Rows
    Dim strTest As String = DataBinder.Eval(myRow.DataItem, "EmailSubject")
Next

if I change the column to a Template field then EmailSubject = myRow.FindControl("EmailSubject") works but I was hoping for a more direct way of getting a column value

EmailSubject = myRow.Cells(4).Text also works but is not flexible if I change the column order

Thanks

Craig

0
craigbtx
4/25/2008 3:42:58 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
1754 Views

Similar Articles

[PageSpeed] 41

Try:

 

Dim strTest As String = CType(e.Row.DataItem, DataRowView)("EmailSubject").ToString()

 


If a post helps me I'll always eventually mark it as an answer. But I frequently don't mark it right away because I feel once a thread is marked as answered, discussion tends to end. And I like to discuss things a bit.
0
tmpuzer
4/25/2008 7:15:04 PM

Also

In a Template Field
Container.DataItem("LastLoggedOnCount")

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server"
            Text='<%# fPercentage(Container.DataItem("LastLoggedOnCount")) %>'>
        </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

0
craigbtx
4/28/2008 8:16:37 PM

 I didn't understand your last post.  Was that another question or a solution??


If a post helps me I'll always eventually mark it as an answer. But I frequently don't mark it right away because I feel once a thread is marked as answered, discussion tends to end. And I like to discuss things a bit.
0
tmpuzer
4/29/2008 1:27:16 AM
craigbtx :

Also

In a Template Field
Container.DataItem("LastLoggedOnCount")

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server"
            Text='<%# fPercentage(Container.DataItem("LastLoggedOnCount")) %>'>
        </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

If you wanted to access the Value of a Label COntrol thats inside Template Column fields then use FindControl Method and have it on GridView's RowDataBoundEvent like

Protected Sub GridView1_RowDataBound1(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim str As String
        Dim l As Label= DirectCast(e.Row.Cells(1).FindControl("Label1"), Label) ' just change the index of cell based on your requirements
        If btn IsNot Nothing Then

            str = l.Text

        End If
    End If
End Sub 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
4/29/2008 2:06:25 AM
Reply:

Similar Artilces:

How to get GridView column values while looping through the columns?
Hi everybody, I'm trying to figure out how can I get values from DataFields while  looping through the Grid rows. Here is what I'm trying to do:GridViewRow row = null; for (int i = 0; i < this.ProfilesGrid.Rows.Count; i++ ) {row = this.ProfilesGrid.Rows[i];   CheckBox chkbtnApproved = row.FindControl("chkApproved") as CheckBox ;if (chkbtnApproved != null) {if (chkbtnApproved.Checked == true) {int RegID = (int)this.ProfilesGrid.DataKeys[i].Value ;   //PersonName = row.DataItem["FirstName"] + " " + row.DataItem["LastNam...

Getting column value from a gridview control
I have a grid view control and has one datakey and other columns. In my grid view I have an Edit Control and a Delete Control. 1) When I press Edit control, I am getting datakey value as expected. But I am not getting other column name i.e. pdf_filename 2) when I press Delete control, I should get the datakey value. But I am not getting I am using c#  Please help me Hi vmk, Could you be a littlemore elaborate? like how have you bound your grid? 1.Columns autogenerated 2.Using TemplateFields 3.Using BoundFields.Regards,NaveenPlease remember to click Mark as Answer on the pos...

Get Value from Hidden Column in Gridview control
I have managed to get the value from my hidden field by using the SelectedIndexChanged event and the following line of code:string keyValue = GridView1.SelectedDataKey.Value.ToString()I would however prefer to get access to the hidden column value on the GridView1_RowDataBound event, so that I can then evaluate each row against the hidden columns value and decide whether or not to display the edit button in each row. Can I do this a different way? You can use e.Row.DataItem("field name") in the RowDataBound event -  as long as the field is in your SQL statement doesn't m...

Get a Clicked Column Index Integer value for a GridView column using the Sorting Event Handler
I am creating a GridView nested within a UpdatePanel and I got the sorting, paging all down to a sciene using the GridView events handlers. Now, I stumbled to a minor problem that I can't seem to figure out how to go about it. When sorting, I would like the heading color of the clicked sorted column to change (using CSS). I can't seem to dynamically pass the value of the clicked column index to the method. I am using the following reference to change the color of the column but I cannot seem to retreive the value of the clicked index in integer value: GridView1.Columns(trying to...

How to get display column value in dddw column
Using PB 9. Have a DW with a column of dddw style. Once the user selects a value in the dddw column, how can I get the data column value and the display column value? Thanks. On Nov 25, 10:15=A0am, SamRAm wrote: > Using PB 9. > Have a DW with a column of dddw style. > Once the user selects a value in the dddw column, how can I > get the data column value and the display column value? > Thanks. data value; dw_1.object.column[row] dw_1.getitem<XXX>(row, 'column') display string; ls_display =3D dw_1.describe("evaluate('lookupdisplay(column...

Hide Gridview column based on the column value
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid Programmatically. The Grid is populated based on a dropdown selection Gridview has 4 columns, LID(item template column) ,LVal (Item Template and an Edit Item template column), Lookupid (Item Template and an Edit Item template column) and "Edit" link 4 of 10 Dropdown selections have values in Column 3 (lookupid), rest dont. When they dont have values i want to hide that column 3. Of course i can ...

How to get any column value in GridView
Hi All,              I have a gridview where in 1st row it has Checkbox control and there are four more columns there like  Select All Group Name CUSIP Address Checkbox 1 Vikrant 0001 Mumbai Checkbox 1 Amrita 0002 Bilaspur Checkbox 2 Ramesh 0003 Mumbai  So my requirement is I have a button below the gridview and when click to button it will find for which of the CheckBox is selected and with the selected checkbox it will find the value of Group ...

how to get a column value from gridview
 hi all, i have a gridview, it consists of different columns, projectid is one of the column which is also displayed in gridview. i want this projectid from gridview.Based on this i will pass parameter from this page to other page and i will extract data onto another page. how can i achieve this. and also can i generate hyperlink during runtime ? please reply me it's urgent. thanks in advance The easiest would be to bind the hyperlink in your gridview using the projectid in the querystring.  Then it will be available to the page it links to. Rob Millswww.d...

Get gridview column values
I have a gridview listing products and in each row is a text box for the user to enter a quantity and an 'add to cart' button. I have an add to cart function and I need to pass the values from the selected row in the gridview to this function (ProductID, Quantity etc.) so I have an onclick event for the add to cart button but I cannot figure out how to get the values from the specify gridview row in order to pass them to my function. I've tried Gridview1.SelectedRow.Cells(0).Text but this only seems to work with the bound fields and not template fields (such as the quantity textbox on each...

GridView and How to get value of a column
I would like to retrive the value of a cell in my GridView, it is a username, so that I can use it as a string to do something with it. I have a select command button and then a databound column Username. Don't laugh but here is what I have. Me.GridView2.DataSource = Roles.GetRolesForUser(Me.GridView1.SelectedRow.DataItemIndex.ToString) Thank you, Hi ,Jack:You can do this in the selectedIndexChanged event.protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)    {           ...

Getting values from a gridview column
Hi All, Here is my problem, I have a gridview that is using an objectdatasource from an SQL DB. I am wanting to check one of the bound coumns in the gridview for a certain value. Here is the code for my gridview: ' Visible="false" /> ' AlternateText='' /> ...

Getting column value from a gridview
Hi All,  I got a gridview with several columns in it.  I created a "Select" commandfield for column1 and datafield for column2 is pointing to ID of the table. When I clicked on column1 I want to get the ID value so I can redirect to another page with that value.  Anyone? Thanks, Steve Hiuse some similar event handler for the grid view   void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        int selected = e.NewSelectedIndex;      &nbs...

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: http://forums.asp.net/t/1069245.aspx 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 to Get a value in an invisible column of gridview?
Dear VB.NET Proz, I have design a gridview with the following template therein, <asp:BoundField DataField="IDX" HeaderText="Date" Visible="False"><asp:TemplateField><ItemTemplate>         <asp:LinkButton ID="linkbutton1" runat="server" OnClick="linButton_Click">Action</asp:LinkButton></ItemTemplate></asp:TemplateField>  So when onclick, it will call my behind code as follow,     Protected Sub linButton_Click(...

Web resources about - How do you get a column value from a gridview column - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/20/2015 1:12:56 AM