Solved

ASP.NET C# GridView EditTemplate

Posted on 2011-02-16
6
614 Views
Last Modified: 2012-06-27
I am using Template Field in my GridView, there are ItemTemplate and EditTemplate in it.
<asp:TemplateField HeaderText="YM1 Actual">
                    <ItemTemplate>
                        <asp:Label ID="lblProcessActualSelYM1" runat="server" Text='<%# Eval("PROCESS_ACTUAL_SEL_YM1") %>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlProcessActualSelYM1" runat="server" Text='<%# Bind("PROCESS_ACTUAL_SEL_YM1") %>' CssClass="selDropDownList"></asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>

Open in new window


However, under certain condition, say, if I have a status field store in my database, and if its value is set to 2, then I want to disable that EditTemplate, so that when user click the Edit button, it will only show the ItemTemplate.

In other words, it should be just work like the following code
 
<asp:TemplateField HeaderText="YM1 Actual">

  <ItemTemplate>
    <asp:Label ID="lblProcessActualSelYM1" runat="server" Text='<%# Eval("PROCESS_ACTUAL_SEL_YM1") %>'></asp:Label>
  </ItemTemplate>

</asp:TemplateField>

Open in new window

0
Comment
Question by:mawingho
6 Comments
 
LVL 9

Accepted Solution

by:
xav056 earned 167 total points
ID: 34912979
the simplest way would be to hide the edit button when the value is 2
you can trap that in thr rowdatabound event of the gridview,
check for the value if it is two and if it is hide the edit button
0
 

Author Comment

by:mawingho
ID: 34912987
You know, other column in that row still allowed to edit..
only one column is not allowed.
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 167 total points
ID: 34912989
Hi, try this link

http://aspalliance.com/1125
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mawingho
ID: 34912996
If I cannot solve this, I think the best workaround is to
create a label control
and set the visible value of the drop down list and the label control
0
 
LVL 13

Assisted Solution

by:agarwalrahul
agarwalrahul earned 166 total points
ID: 34913066
Right this code in the GridView1_RowDataBound Event and hide the column. In Controls(6) the 6th is number of that column to be Hide on value in database is 2 to disable editing.

If e.Row.RowType = DataControlRowType.Header Then
         e.Row.Controls(6).Visible = False
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
         e.Row.Controls(6).Visible = False
       End If
0
 

Author Closing Comment

by:mawingho
ID: 34913073
I have already done it, but thanks anyway
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Set cookies HttpOnly and Secure 4 62
C# Error - Add Failed 12 52
Asp.net mvc entity issue 6 20
Asp.net mvc 5 5 22
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now