473,289 Members | 2,087 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,289 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 4467
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.