[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

create error when gridview update text field has too many characters.

Posted on 2009-05-09
2
Medium Priority
?
414 Views
Last Modified: 2012-05-06
I have a gridview that has update capabilities. How do I create an error message when there are more that say 20 characters? Thanks in advance
<asp:GridView ID="eventsGrid" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID"
         DataSourceID="AccessDataSource1" 
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"/>
                <asp:TemplateField HeaderText="Event" SortExpression="event">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtUpdateEvent" runat="server" Text='<%# Bind("event") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>                   
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("event") >'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>        
                <asp:CommandField ButtonType="Button" ShowEditButton="True" />
            </Columns>
 
Protected Sub EventsGrid_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles eventsGrid.RowUpdated
        If e.Exception IsNot Nothing Then
        lblError.Text = "An exception ocurred." & e.Exception.Message
        e.ExceptionHandled = True
       e.KeepInEditMode = True
         ElseIf e.AffectedRows = 0 Then
          lblError.Text = "No rows Updated"
 End If
End Sub

Open in new window

0
Comment
Question by:designaire
[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
2 Comments
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 500 total points
ID: 24346149
There is no need to raise an error in case there are more than 20 character as you can limit your user to enter maximum of 20 (or whatever maximum limit is) characters by using the MaxLength property of the TextBox in ASP.NET.

Add the part formatted bold in your ASPX code and you are done.

<asp:TextBox ID="txtUpdateEvent" runat="server" Text='<%# Bind("event") %>' MaxLength="20"></asp:TextBox>
0
 

Author Comment

by:designaire
ID: 24346309
Yes, thank you. It does throw an exception. Maybe because of the below code. I had to set the maximum inthe database also.

Protected Sub EventsGrid_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles eventsGrid.RowUpdated
        If e.Exception IsNot Nothing Then
        lblError.Text = "An exception ocurred." & e.Exception.Message
        e.ExceptionHandled = True
       e.KeepInEditMode = True
         ElseIf e.AffectedRows = 0 Then
          lblError.Text = "No rows Updated"
 End If
End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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