473,406 Members | 2,707 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,406 software developers and data experts.

GridView DataRowBound question

Doing this in VB.NET with VS2008.

I have a simple GridView with two columns. Column1 Header is called
"Reason" and the rows contain a Label called "ReasonL". Column2 header is
called Add/Edit and the row has a LinkButton called "AddEditLB". Basically,
it looks like this.

Reason Add/Edit
ReasonL AddEditLB

All I want to do is make AddEditLB Text to say "Add" if ReasonL is
string.empty and "Edit" if it's not. This is what I tried in the
RowDataBound event and it didn't work:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DataItem("ReasonL").ToString = String.Empty Then
e.Row.DataItem("AddEditLB") = "Add"
Else
e.Row.DataItem("AddEditLB") = "Edit"
End If
End If

End Sub

Can someone tell me what I did wrong?
This is the error msg I got.

ReasonL is neither a DataColumn nor a DataRelation for table DefaultView.

Thanks!
Aug 20 '08 #1
4 1893
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
e.Row.DataItem("AddEditLB") = "Add"
What happens if you try:

e.Row.Cells(2).Text = "Add"
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 20 '08 #2
Mark - This does work, but it only puts the word "Add" or "Edit" in my
column where I had my AddEdit LinkButton. It's just text and no LinkButton.
I want to assign the text for the LB in each row. My users need to have
access to the LB.
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>e.Row.DataItem("AddEditLB") = "Add"

What happens if you try:

e.Row.Cells(2).Text = "Add"
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 20 '08 #3
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:O8**************@TK2MSFTNGP03.phx.gbl...

[top-posting corrected]
>>e.Row.DataItem("AddEditLB") = "Add"

What happens if you try:

e.Row.Cells(2).Text = "Add"

This does work, but it only puts the word "Add" or "Edit" in my column
where I had my AddEdit LinkButton. It's just text and no LinkButton. I
want to assign the text for the LB in each row. My users need to have
access to the LB.
OK, then. How about:

DirectCast(e.Row.Cells(2).FindControl("AddEditLB") , Button).Text = "Add"

The syntax may not be 100% accurate, as I never go anywhere near VB.NET, but
should be close enough...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 20 '08 #4
This worked perfectly. Now I need to do some reading on what DirectCast
actually does. Learned something new today. Thanks!

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:O8**************@TK2MSFTNGP03.phx.gbl...

[top-posting corrected]
>>>e.Row.DataItem("AddEditLB") = "Add"

What happens if you try:

e.Row.Cells(2).Text = "Add"

This does work, but it only puts the word "Add" or "Edit" in my column
where I had my AddEdit LinkButton. It's just text and no LinkButton. I
want to assign the text for the LB in each row. My users need to have
access to the LB.

OK, then. How about:

DirectCast(e.Row.Cells(2).FindControl("AddEditLB") , Button).Text = "Add"

The syntax may not be 100% accurate, as I never go anywhere near VB.NET,
but should be close enough...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 20 '08 #5

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

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
0
by: =?Utf-8?B?R3JpZFZpZXcgTmV3Ymll?= | last post by:
I have a business requirement stating that when the Location Type is "C" the user should not be able to update the StoreNumber. So, when the user clicks the "edit" button in the GridView for a...
2
by: pvong | last post by:
Doing this in VB.NET I have a gridview RowDataBound. I want to do a test on each row column (12). Some of the rows have NULL value. This is the error message I'm getting. Object cannot be...
1
by: bruce barker | last post by:
when do you clear PriceChange which is a running total? -- bruce (sqlwork.com) pvong wrote:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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...
0
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
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...

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.