看看这个示例代码:(下面的问题)
<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/