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

x
?
Solved

Make a TemplateField ReadOnly in gridView when Edit button is clicked

Posted on 2010-08-30
3
Medium Priority
?
2,426 Views
Last Modified: 2012-05-10
Hello.
I have a gridView with Edit button. My columns are template columns such as:

<asp:TemplateField HeaderText="Start Date">
                    <ItemTemplate>
                        <asp:Label ID="lblStartDate1" runat="server" Text='<%# Eval("StartDate")>'></asp:Label>                        
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtStartDate1" Text='<%# Eval("StartDate")%>' runat="server"></asp:TextBox>                        
                    </EditItemTemplate>                    
                </asp:TemplateField>

My gridView is nested. So whenever a row doesn't have children, all columns should be editable, and when a row has children, some columns become summary columns, and should not be editable.
How would I achive this with templateFields? I just want to show a label like it is, not convert it into a textbox.
0
Comment
Question by:yanasizonenko
[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
3 Comments
 
LVL 60

Expert Comment

by:HainKurt
ID: 33560645
use ReadOnly="True|False"

0
 
LVL 31

Accepted Solution

by:
MlandaT earned 2000 total points
ID: 33560761
Also consider moving both controls into the ItemTemplate. Then show/hide the label/textbox based on you condition for showing the field.

in ASPX:

<asp:TemplateField HeaderText="Start Date">
       <ItemTemplate>
              <asp:Label ID="lblStartDate1" runat="server" Text='<%# Eval("StartDate")>'></asp:Label>                        
              <asp:TextBox ID="txtStartDate1" Text='<%# Eval("StartDate")%>' runat="server"></asp:TextBox>
       </ItemTemplate>                
</asp:TemplateField>

in ASPX.VB.. DataBound event of gridView:

If e.Row.RowType = DataControlRowType.DataRow Then

     Dim myTextBox = CType(e.Item.Cells(index).Controls(1), TextBox)
     Dim myLabel = CType(e.Item.Cells(index).Controls(0), Label)
     
     myTextBox.Visible =Not FIELD_SHOULD_BE_READONLY_CONDITION
     myLabel.Visible = FIELD_SHOULD_BE_READONLY_CONDITION

End If
0
 

Author Closing Comment

by:yanasizonenko
ID: 33572448
I used the code on RowDataBound event
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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

604 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