Click here to Skip to main content
15,887,952 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello, I am a total noob and am just trying to cobble a small user front end together with 2010 MSVWD express. I use a sql server with a table. A front end asp.net vb web page with a gridview. Gridview needs to update a table with user input. I'm having trouble limiting the amount of characters the user can enter in each field. If they enter too many in a given field they get an error. Can anybody help me figure this out?

This is the code I'm using:
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="REWTSEquip1" EnableModelValidation="True" AllowPaging="True" 
        AutoGenerateEditButton="True" PageSize="4">
        <columns>
            <asp:BoundField DataField="MANUFACTURER" HeaderText="MANUFACTURER" 
                SortExpression="MANUFACTURER"  />
            <asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL" 
                 />
            <asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" 
                SortExpression="DESCRIPTION"  />
            <asp:BoundField DataField="SERIAL" HeaderText="SERIAL" 
                SortExpression="SERIAL" />
            <asp:BoundField DataField="EQUIP_ID" HeaderText="EQUIP_ID" 
                SortExpression="EQUIP_ID"  />
            <asp:BoundField DataField="CUSTOMER_NUMBER" HeaderText="CUSTOMER_NUMBER" 
                SortExpression="CUSTOMER_NUMBER"  />
            <asp:BoundField DataField="SERVICECOUNT" HeaderText="SERVICECOUNT" 
                SortExpression="SERVICECOUNT" />
            <asp:BoundField DataField="LOCATION" HeaderText="LOCATION" 
                SortExpression="LOCATION" />
            <asp:BoundField DataField="RECEIVED" HeaderText="RECEIVED" 
                SortExpression="RECEIVED" />
            <asp:BoundField DataField="CONDITION" HeaderText="CONDITION" 
                SortExpression="CONDITION" />
            <asp:BoundField DataField="TECHNICIAN" HeaderText="TECHNICIAN" 
                SortExpression="TECHNICIAN" />
            <asp:BoundField DataField="NOTES" HeaderText="NOTES" 
                SortExpression="NOTES" />
            <asp:BoundField DataField="DISPOSITION" HeaderText="DISPOSITION" 
                SortExpression="DISPOSITION" READONLY="true"/>
        </columns>
    
    <asp:SqlDataSource ID="REWTSEquip1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MyConnectionstring %>" 
        SelectCommand="usp_Process" 
        SelectCommandType="StoredProcedure" 
        
        InsertCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)" 
        UpdateCommand="INSERT INTO REWTSEquipment(MANUFACTURER, MODEL, DESCRIPTION, SERIAL, EQUIP_ID, CUSTOMER_NUMBER, SERVICECOUNT, LOCATION, RECEIVED, CONDITION, TECHNICIAN, NOTES, DISPOSITION) VALUES (@MANUFACTURER, @MODEL, @DESCRIPTION, @SERIAL, @EQUIP_ID, @CUSTOMER_NUMBER, @SERVICECOUNT, @LOCATION, @RECEIVED, @CONDITION, @TECHNICIAN, @NOTES, @DISPOSITION)">
        <insertparameters>
            <asp:Parameter Name="MANUFACTURER" />
            <asp:Parameter Name="MODEL" />
            <asp:Parameter Name="DESCRIPTION" />
            <asp:Parameter Name="SERIAL" />
            <asp:Parameter Name="EQUIP_ID" />
            <asp:Parameter Name="CUSTOMER_NUMBER" />
            <asp:Parameter Name="SERVICECOUNT" />
            <asp:Parameter Name="LOCATION" />
            <asp:Parameter Name="RECEIVED" />
            <asp:Parameter Name="CONDITION" />
            <asp:Parameter Name="TECHNICIAN" />
            <asp:Parameter Name="NOTES" />
            <asp:Parameter Name="DISPOSITION" />
        </insertparameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="EQUIPID" QueryStringField="Equipid" 
                Type="String" />
        </SelectParameters>
        <updateparameters>
            <asp:Parameter Name="MANUFACTURER" />
            <asp:Parameter Name="MODEL" />
            <asp:Parameter Name="DESCRIPTION" />
            <asp:Parameter Name="SERIAL" />
            <asp:Parameter Name="EQUIP_ID" />
            <asp:Parameter Name="CUSTOMER_NUMBER" />
            <asp:Parameter Name="SERVICECOUNT" />
            <asp:Parameter Name="LOCATION" />
            <asp:Parameter Name="RECEIVED" />
            <asp:Parameter Name="CONDITION" />
            <asp:Parameter Name="TECHNICIAN" />
            <asp:Parameter Name="NOTES" />
            <asp:Parameter Name="DISPOSITION" />
        </updateparameters>
    
    </form>
</body>
</html>


[Edit - Added pre code tags, edited for spelling]
Posted
Updated 14-Jun-11 6:15am
v2

1 solution

You need to set maxlength for the fields based on database field length.
 
Share this answer
 
Comments
AnthonyGC 14-Jun-11 12:52pm    
I've read about that but am having trouble understanding how to incorporate that in to my code. How would that look with one of the columns provided in my code?

THank you
thatraja 14-Jun-11 12:56pm    
where are the textboxes you are entering your inputs? Include full code in your question. Textbox contains maxlength property so set the value based on database field length.
AnthonyGC 14-Jun-11 13:18pm    
I don't know what your talking about. This si the full page from head to head.

This is the back code page

Partial Class REWTSManage
Inherits System.Web.UI.Page

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

End Sub

End Class

I loaded this page and it works.
AnthonyGC 14-Jun-11 13:22pm    
Ah wait. my grid fields weren't converted to template fields yet. Is that what your talking about?
thatraja 14-Jun-11 13:39pm    
Yes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900