?
Solved

ASP.NET C# GridView EditTemplate

Posted on 2011-02-16
6
Medium Priority
?
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Accepted Solution

by:
xav056 earned 501 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 501 total points
ID: 34912989
Hi, try this link

http://aspalliance.com/1125
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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:Rahul Agarwal
Rahul Agarwal earned 498 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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