Solved

ASP.NET C# GridView EditTemplate

Posted on 2011-02-16
6
652 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 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