편집 모드 일 때 유효성을 검사하려는 gridview가 있습니다. 어떻게해야합니까?Gridview 유효성 검사
아래는 내 Gridview 및 그 첫 시도입니다.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"
Width="387px" DataKeyNames = "APPID" AllowPaging="True">
<PagerSettings Mode="NextPreviousFirstLast" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="APPName" HeaderText="Application"
SortExpression="APPName" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:CommandField AccessibleHeaderText="Edit" ButtonType="Image"
DeleteImageUrl="~/images/bttnDelete.gif"
EditImageUrl="~/images/bttnEdit.gif" HeaderText="Action"
ShowDeleteButton="True" ShowEditButton="True"
ShowHeader="True" CancelImageUrl="~/images/bttnCancel.gif"
UpdateImageUrl="~/images/bttnSave.gif" InsertVisible="False" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
첫 번째 시도
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowState = DataControlRowState.Edit Then
Dim savebtn As ImageButton = DirectCast(e.Row.Cells(2).Controls(0), ImageButton)
savebtn.ValidationGroup = "grd"
'set up Name Textbox
Dim txtname As TextBox = DirectCast(e.Row.Cells(0).Controls(0), TextBox)
txtname.ValidationGroup = "grd"
Dim reqval As New RequiredFieldValidator
reqval.ID = "reqnam"
reqval.ValidationGroup = "grd"
reqval.ErrorMessage = "Application Name Cannot Be Empty"
reqval.ControlToValidate = txtname.UniqueID
End If
"gridview edit validation asp.net"으로 검색하면 많은 도움이됩니다. –