Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET C# GridView EditTemplate

Posted on 2011-02-16
6
Medium Priority
?
661 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Independent Software Vendors: 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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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