Gridview row editing fields based on row data

Is there a way to change row editable fields in a databound gridview based on the rows data.

For example letting a user edit all his and his fellows fields but preventing him from changing specific fields in his boss data on the same gridview?

Help will be great fully appreciated.

Thanks

0
Itay
3/31/2008 10:42:21 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
915 Views

Similar Articles

[PageSpeed] 46

If I understand what you are saying is that you want to only allow a user to Edit certain rows within the GridView. If so, yes, you certainly can do this. What I would do is hide/display the Edit Button for a row based on the user's role or permissions. This can easily be done via the RowDataBound event handler by retrieving a reference to the Edit Button, retrieving the user's roles or permissions, and then setting the Button's Visible property accordingly.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
3/31/2008 12:33:39 PM

Hi thanks for the answer but that is not what i ment

i am not trieng to allow or deny a user from editing a specific row

i want to change the editable fields within the row based on the row data

Is this clear enough?

0
Itay
3/31/2008 2:42:48 PM

It's a bit more complex, but yes you can do it. I'd create Panels within each EditItemTemplate. One Panel would contain a Label and the other Panel would contain the editable control. Then, declaratively using a data-binding expression or using the RowDataBound event, you could hide/display the appropriate Panel dependent on your data.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
3/31/2008 4:07:23 PM

Hi

still can't get it to work.

tried using the gridview row edit event but i read that its fired before the row databounding is obtained so its not possible to call the controls from there.

tried using the databound event of the control in the edit template but  "no success".

 

How can i manipulate the panels in the edit template?

perhaps a bit of code sample of manipulating controls in the edit template on the rowdatabound event?

thanks in advance.

0
Itay
4/7/2008 5:01:49 PM

Something like this:

ASPX 

<asp:templatefield>
	<edititemtemplate>
		<asp:label id="Label1" runat="server" text='<%# Eval("MyField") %>' />
		<asp:textbox id="TextBox1" runat="server" text='<%# Bind("MyField") %>' />
	</edititemtemplate>
</asp:templatefield>

CODE-BEHIND 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
	GridViewRow gvr = e.Row;

	if ((gvr.RowType == DataControlRowType.DataRow) && ((gvr.RowState & DataControlRowState.Edit) > 0))
	{
		Label Label1 = gvr.FindControl("Label1") as Label;
		TextBox TextBox1 = gvr.FindControl("TextBox1") as TextBox;

		if (this.User.IsInRole("Manager"))
		{
			TextBox1.Visible = true;
			Label1.Visible = false;
		}
		else
		{
			TextBox1.Visible = false;
			Label1.Visible = true;
		}
	}
}

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/7/2008 5:12:35 PM
Reply:

Web resources about - Gridview row editing fields based on row data - 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: 1/18/2016 2:43:43 AM