Gridveiw所需的字段验证器 [英] Required Field Validator for Gridveiw
问题描述
我有Gridveiw有7列,其中3列是下拉列表
我的要求 - >我需要在更新行或添加新行之前验证这3列。
如果选择第一列(测试/窗口),所有3列都是相互关联的frame)在第二列(测试对象)中填充值并基于第二列填充第3列(测试对象),但现在问题是在填充所有列(即所有3列)后用户可以去返回并将第二列更改回--Select--并且可以更新我需要防止这种情况发生,所以我如何验证所有列。
以下是代码
Hi, I have Gridveiw which has 7 Columns and out of that 3 columns are drop down list
My Requirement--> I need to validate this 3 Columns before updating the row or during adding the new rows.
All the 3 columns are interrelated if you select the first column(Test/window frame) the values get populated in the second column(Test Object)and based on the second column the 3rd column(Test Object) gets populated , but now the problem is after populating all the columns(i.e all the 3 columns) user can go back and change the 2nd column back to "--Select--" and can update I need to prevent this from happening so how do i validate all the columns.
Below is the code
<asp:GridView ID="gvTestScriptComponent" runat="Server" CssClass="GridViewStyle" AutoGenerateColumns="False"
CellPadding="4" ForeColor="Black" DataKeyNames="ComponentID"
ShowFooter="true" Height="110px" Style="margin-right: 0px" Width="990px" BackColor="White"
OnRowDataBound="gvTestScriptComponent_RowDataBound" AutoGenerateEditButton="True"
OnRowEditing="gvTestScriptComponent_RowEditing" OnRowCancelingEdit="gvTestScriptComponent_RowCancelingEdit"
OnRowUpdating="gvTestScriptComponent_RowUpdating" OnRowDeleted="gvTestScriptComponent_RowDeleted"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
OnRowCommand="gvTestScriptComponent_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ComponentID" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblComponentID" runat="server" Height="20px" Text='<%#Eval("ComponentID")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Options" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="images/delete.ico" CausesValidation="false"
CommandName="DeleteRow" OnClick="btnDelete_Click" OnClientClick='return confirm("Are you sure you want to delete?");' />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
CommandName="SaveRow" OnClick="btnSave_Click" />
</FooterTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="TestWindow/Frame Name" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblTestWindow" runat="server" Height="20px" Text='<%#Eval("BrowserPage")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:DropDownList ID="ddlTestWindow" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlTestWindow_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterTestWindow" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterTestWindow_SelectedIndexChanged">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Object" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblTestObject" runat="server" Height="20px" Text='<%#Eval("ObjectName")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:DropDownList ID="ddlTestObject" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlTestObject_SelectedIndexChanged" >
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterTestObject" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterTestObject_SelectedIndexChanged">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Operation" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblTestOperation" runat="server" Height="20px" Text='<%#Eval("Action")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:DropDownList ID="ddlTestOperation" runat="server" Visible="true">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterTestOperation" runat="server" Visible="true">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Data" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblTestData" runat="server" Height="20px" Text='<%#Eval("TestData")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:TextBox ID="txtTestData" runat="server" Text='<%# Bind("TestData") %>' Visible="true">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFooterTestData" runat="server" Visible="true"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ReusableOutputData" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblReUseableOutputData" runat="server" Height="20px" Text='<%#Eval("ReUsableOutputData")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:TextBox ID="txtReUseableOutputData" runat="server" Text='<%# Bind("ReUsableOutputData") %>'
Visible="true">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFooterReUseableOutputData" runat="server" Visible="true"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Step Description" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblStepDescription" runat="server" Height="20px" Text='<%#Eval("Steps")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:TextBox ID="txtStepDescription" runat="server" Text='<%# Bind("Steps") %>' Visible="true">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFooterStepDescription" runat="server" Visible="true"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" HorizontalAlign="Justify"
VerticalAlign="Middle" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
<EmptyDataTemplate>
<table>
<tr style="background-color: #999999;">
<th>
Option
</th>
<th>
Test Window
</th>
<th>
Test Object
</th>
<th>
Test Operation
</th>
<th>
Test Data
</th>
<th>
ReUseableOutputData
</th>
<th>
StepDescription
</th>
</tr>
<tr>
<td headers="Option">
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
CommandName="FirstSaveRow" OnClick="btnSave_Click" />
</td>
<td headers="Test Window">
<asp:DropDownList ID="ddlFooterTestWindow" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterTestWindow_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td headers="Test Object">
<asp:DropDownList ID="ddlFooterTestObject" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterTestObject_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td headers="Test Operation">
<asp:DropDownList ID="ddlFooterTestOperation" runat="server" Visible="true">
</asp:DropDownList>
</td>
<td headers="Test Data">
<asp:TextBox ID="txtFooterTestData" runat="server" Visible="true"></asp:TextBox>
</td>
<td headers="ReUseableOutputData">
<asp:TextBox ID="txtFooterReUseableOutputData" runat="server" Visible="true"></asp:TextBox>
</td>
<td headers="StepDescription">
<asp:TextBox ID="txtFooterStepDescription" runat="server" Visible="true"></asp:TextBox>
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
推荐答案
refer below links:-
http://stackoverflow.com/questions/19131992/how-to-place-a-required-field-validator-inside-a-gridview-textbox[^]
< a href=\"http://stackoverflow.com/questions/5775856/textbox-inside-gridview-validation\">http://stackoverflow.com/questions/5775856/textbox-inside-gridview-validation[^]
http://www.aspsnippets.com/Articles/Using-ASPNet-RequiredFieldValidator-for-TextBox-inside-GridView-TemplateField-ItemTemplate.aspx[^]
refer below links:-
http://stackoverflow.com/questions/19131992/how-to-place-a-required-field-validator-inside-a-gridview-textbox[^]
http://stackoverflow.com/questions/5775856/textbox-inside-gridview-validation[^]
http://www.aspsnippets.com/Articles/Using-ASPNet-RequiredFieldValidator-for-TextBox-inside-GridView-TemplateField-ItemTemplate.aspx[^]
Add RequiredFieldValidator for dropdownlist.
Add RequiredFieldValidator for dropdownlist.
<asp:DropDownList ID="DropDownList1" runat="server" Width="100px">asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList1" Display="dynamic"
ErrorMessage="Please Select the Rating" InitialValue="Select Rating">asp:RequiredFieldValidator>
Refer:Validate dropdownlist inside gridview[^]
This may help.
Refer:Validate dropdownlist inside gridview[^]
This may help.
这篇关于Gridveiw所需的字段验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!