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

GridView: conditional editing

JDC
Hi all,

How do I allow or disallow editing in a GridView on a row-by-row basis,
depending on the value of a field in that row?

TIA, JC

May 17 '06 #1
4 4471
Use the RowDataBound event handler, and do something like

TextBox MyTextBox = (TextBox)e.Row.FindControl("IDOfControl");

if (MyTextBox.Text == "ValueYouAreLookingFor")
{
LinkButton MyLinkButton = (Linkbutton)e.Row.FindControl("IDOfEditLinkbutton" );
MyLinkButton.visible = false;
}

"JDC" wrote:
Hi all,

How do I allow or disallow editing in a GridView on a row-by-row basis,
depending on the value of a field in that row?

TIA, JC

May 17 '06 #2
JDC
Thanks, that seems to be the right track. However, I'm trying to hide
(or disable) a CommandField (which uses images, not links), and I can't
figure out what control ID to pass to FindControl():
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView vw = (DataRowView)e.Row.DataItem;

if (vw["Locked"].ToString() == "True")
{
//e.Row.FindControl(String.Format("Edit${0}",
e.Row.RowIndex)).Visible = false;
}
}
}

Any ideas?

Cheers, JC

May 17 '06 #3
Turn your CommandField into a TemplateField, you can then set the ID of the
ImageButton that provides the edit command.

"JDC" wrote:
Thanks, that seems to be the right track. However, I'm trying to hide
(or disable) a CommandField (which uses images, not links), and I can't
figure out what control ID to pass to FindControl():
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView vw = (DataRowView)e.Row.DataItem;

if (vw["Locked"].ToString() == "True")
{
//e.Row.FindControl(String.Format("Edit${0}",
e.Row.RowIndex)).Visible = false;
}
}
}

Any ideas?

Cheers, JC

May 17 '06 #4
JDC
Yep, that works perfectly, thanks. Better than I originally envisaged,
actually, as my "status" flag was already another template column, and
now I have just one "smart" template column.

Cheers, JC

May 18 '06 #5

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

Similar topics

1
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
4
by: P. Yanzick | last post by:
Hello, I've been playing with master/detail views as well as editing in the gridview, and I ran across a strange problem that I am not exactly sure where to go to try to solve. I have 2...
1
by: Kyle K. | last post by:
I would like to build my data pages such that the top of the page contains a GridView showing the data with 'Enable Select = true'. Below that I would like to have a FormView, that by default is...
1
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
3
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have a gridview which I added a <asp:CommandField EditText="E" CancelText="C" UpdateText="U" ButtonType="Link" ShowEditButton="True" /> my gridview looks like this <asp:GridView...
5
by: =?Utf-8?B?Z3V5?= | last post by:
How do you enable editing in a GridView programatically rather than via its Tasks menu? Guy
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
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
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
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...
0
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...

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.