Solved

ASP.NET C# GridView EditTemplate

Posted on 2011-02-16
6
633 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web site error 3 41
Example works but why do I need to click twice on button 4 43
.NET 2008 VB and C# 6 28
Linq asp.net mvc 13 12
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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