asp.net - 将验证器添加到在绑定(bind)字段的编辑模式下创建的 gridview 文本框

标签 asp.net validation

看看这个示例代码:(下面的问题)

<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,添加一个参数等等。

问题是,当用户点击编辑时,我们会得到一个文本框来编辑列值。 我想在执行更新之前验证用户输入的数据和新的 数据传播回服务器。如何?

10 倍很多!

最佳答案

您需要convert the BoundField into a TemplateField .然后您可以将验证器添加到实际的 TextBox 控件。

关于asp.net - 将验证器添加到在绑定(bind)字段的编辑模式下创建的 gridview 文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524296/

相关文章:

c# - 在 httpcontext asp.net core 上缓存对象

javascript - 如何将标签添加到Asp.net文本框?

javascript - 如何从快速验证器 escape() 函数中排除字符

php - Laravel - 如何验证西里尔字母

javascript - 如何在 ASP.NET 上实现 Google Places 文本框预测?

c# - 未观察到任务的异常

c# - MVC3 十进制字段未正确验证

javascript - 为什么 AUI 的 Dropdown 在文本字段验证之前需要验证火拳

javascript - jQuery/javascript 和嵌套的 if 语句

asp.net - ASP.NET 中项目结构的最佳实践?