2012-10-09 59 views
0

我的GridView如下:如何將驗證添加到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字段,以便它僅接受一個I​​nDesign中,XML,CorelDraw中,StaticImage文件類型,其中擴展名應該是一個的

.indd,.TIF,.WMF,.idms,.EPS,.PDF,.XML,.inds,.EMF,JPG格式,文件Freehand,.GIF,.AI,.u01

如何在用戶添加/編輯時執行此驗證檢查?

+0

那你試試也結合? – Buzz

+0

顯示您的編輯模板或表單並控制要應用驗證的位置。 – yogi

+0

我不能使用我的客戶指定的編輯模板 – user1514274

回答

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); 

您可以DataViewfilterDataView

var dataView = new DataView(YourDataTable); 
dataView.RowFilter = "FileType == '.indd' OR FileType == '.tif' OR ....."; 
YourGridView.DataSource = dataView ; 
相關問題