2
這是我的gridview,我添加了一個命令字段編輯它將允許編輯網格視圖中的特定值。代碼工作正常.i只需要知道如何爲綁定字段添加必需的字段驗證器和正則表達式驗證器。 據我所知,增加項目模板中的文本框,然後使用的ControlToValidate =」 ID」可以驗證,但有對綁定字段網格視圖內的綁定字段元素的必需字段和正則表達式驗證器
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" RowStyle-HorizontalAlign="Center"
style="top: 538px; left: 216px; position: absolute; height: 133px; width: 534px"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
Visible="False" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Sr.No.">
<ItemTemplate>
<asp:Label ID="lblserial" runat="server">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FID" HeaderText="Faculty ID" ReadOnly="true"
ItemStyle-HorizontalAlign="Center" SortExpression="FID" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString ="{0:d}" SortExpression="Date" ReadOnly="true"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Theme" HeaderText="Theme" SortExpression="Theme"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Duration" HeaderText="Duration" ItemStyle-HorizontalAlign="Center"
SortExpression="Duration" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Organizer" HeaderText="Role" ItemStyle-HorizontalAlign="Center"
SortExpression="Organizer" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Venue" HeaderText="Venue" SortExpression="Venue" ReadOnly="true"
ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="UpdateDate" HeaderText="UpdateDate" DataFormatString ="{0:d}" ReadOnly="true"
SortExpression="UpdateDate" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<EmptyDataTemplate><h3 align="center" style="font-weight: bold; font-size: large">No Records Found</h3></EmptyDataTemplate>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT * FROM [WorkshopSC_det] WHERE ([FID] = @FID)"
UpdateCommand="UPDATE [WorkshopSC_det] SET [email protected],[email protected] WHERE([email protected]) ">
<SelectParameters>
<asp:SessionParameter Name="FID" SessionField="FID" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Theme"/>
<asp:Parameter Name="Duration" />
<asp:Parameter Name="Organizer" />
<asp:Parameter Name="Role" />
</UpdateParameters>
</asp:SqlDataSource>
希望這可以幫助你 - http://stackoverflow.com/questions/7685853/how-to-give-required-field-validator-to-textbox-in-gridview – mmssaann
而這一次 - HTTP: //www.codeproject.com/Articles/203892/Required-BoundField-in-Gridview – mmssaann
我沒有使用項目模板和文本框,我需要爲綁定字段本身添加RFV –