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 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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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.
|
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...
|
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...
|
by: =?Utf-8?B?Z3V5?= |
last post by:
How do you enable editing in a GridView programatically rather than via its
Tasks menu?
Guy
|
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...
|
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...
|
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"....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |