0

我有gridview如下:

<asp:GridView runat="server" ID="gvOverrideData" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="LightGreen" Width="800" OnRowEditing="OverrideGrid_OnRowEditing" OnRowCancelingEdit="OverrideGrid_OnRowCancelingEdit" OnRowUpdating="OverrideGrid_RowUpdating">
    <HeaderStyle BackColor="LightGray" />
    <Columns>
        <asp:TemplateField HeaderText="Path">
            <ItemTemplate>
                <%# GetOverrideTemplatePath(DataBinder.Eval(Container.DataItem, "Path").ToString())
                %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="FileName" HeaderText="File Name" />
        <asp:BoundField DataField="Extension" HeaderText="File Extension" />
        <asp:BoundField DataField="FileType" HeaderText="File Type" />
        <asp:BoundField DataField="Iteration" HeaderText="Iteration" />
        <asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true"
        ShowCancelButton="true" />
    </Columns>
</asp:GridView>

我想验证该FileType字段,使其仅接受 InDesign、XML、CorelDraw、StaticImage 文件类型,其中扩展名应为以下之一

.indd、.tif、.wmf、.idms、.eps、.pdf、.xml、.inds、.emf、.jpg、.cdr、.gif、.ai、.u01

当用户添加/编辑时,如何执行此验证检查?

4

1 回答 1

0

您可以添加验证before you bind with DataSource

var expression = "FileType == '.indd' OR FileType == '.tif' OR ..... ";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
var foundRows = table.Select(expression);

您还可以DataViewfilter您的DataView

var dataView = new DataView(YourDataTable);
dataView.RowFilter = "FileType == '.indd' OR FileType == '.tif' OR .....";
YourGridView.DataSource = dataView ;
于 2012-10-09T07:49:44.333 回答