添加验证到GridView文本框,在一个绑定字段的编辑模式创建 [英] Adding a validator to the gridview textbox, created in edit-mode of a bound field

查看:187
本文介绍了添加验证到GridView文本框,在一个绑定字段的编辑模式创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来看看这个样本code:(波纹管的问题)

take a look at this sample code: (question bellow)

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AllowSorting="True" DataSourceID="SqlDataSource2" 
    AutoGenerateColumns="False" onrowupdated="GridView1_RowUpdated" 
         DataKeyNames="Product_Id">
    <Columns>
    <asp:ImageField DataImageUrlField="Image_Name" HeaderText="Image_Name" 
           ReadOnly="True" >
    <ItemStyle Width="50px" Height="50px"  Wrap="true"/>
    </asp:ImageField>       
    <asp:BoundField DataField="Product_Id" HeaderText="Product_Id" 
           InsertVisible="False" ReadOnly="True" SortExpression="Product_Id">
    </asp:BoundField>
        <asp:BoundField DataField="Product_Name" HeaderText="Product_Name" 
            SortExpression="Product_Name" />
        <asp:BoundField DataField="Category_Name" HeaderText="Category_Name" 
            SortExpression="Category_Name" ReadOnly="true" />
        <asp:BoundField DataField="Description" HeaderText="Description" 
            SortExpression="Description" />
        <asp:BoundField DataField="Size" HeaderText="Size" 
                 SortExpression="Size" />
        <asp:BoundField DataField="Price" HeaderText="Price" 
                 SortExpression="Price" />
        <asp:CommandField ShowEditButton="True" />
        <asp:CommandField ShowDeleteButton="True" />
    </Columns>
</asp:GridView>

假设我初始化的SqlDataSource,添加参数等。

Assume I initialize an SqlDataSource, add a parameter and so on.

问题是,当用户点击编辑,我们得到一个文本编辑colnumn值。
我想验证数据由用户输入进行更新前和新
数据传回到server.How?

The thing is, that when a user clicks edit we get a textbox to edit the colnumn value. I want to validate the data enter by the user before the update is performed and the new data is propagated back to the server.How?

10倍了很多!

推荐答案

您需要的转换BoundField转换为TemplateField 。然后,你可以验证器添加到实际的TextBox控件。

You need to convert the BoundField into a TemplateField. Then you can add a validator to the actual TextBox control.

这篇关于添加验证到GridView文本框,在一个绑定字段的编辑模式创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆