I have a detail view and gridview in one form. The user enter the information to the detailsview and then everything user entered will show in the gridview. The problem happen when I try to update the gridview, the validation control in the detailsview fired.
If I take away the validation control in the detailsview, everyting work fine.
The question is how can I update the gridview by calling GridView1_RowUpdating and stop the validation control pops the error message from detailsview.
ProtectedSub
GridView1_RowUpdating(sender AsObject,
e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
Dim
lb As
Label = DirectCast(GridView1.Rows(e.RowIndex).FindControl("Label6"),
Label)
Dim
chb As
CheckBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("chkalarm"
), CheckBox)
Dim
ddlone As
DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList3"),
DropDownList)
Dim
ddltwo As
DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList4"),
DropDownList)
Dim
tx1 As
TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("TextBox1"),
TextBox)
Dim
tx2 As
TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("TextBox2"),
TextBox)
Dim
sql AsString
= "UPDATE
dbo.Alarm SET isenable= " & Convert.ToByte(chb.Checked) &
","_
The Controls you want to be validated write the Validation Group in there Markup
like
<asp:requiredfieldvalidator id="RequiredFieldValidator1"
controltovalidate="NameTextBox"
validationgroup="SubmitGroup" // Write this Same "SubmitGroup" To the Controls also on SubmitButton etc.
errormessage="Enter your name."
runat="Server">
</asp:requiredfieldvalidator>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("zip") %>' validationgroup="SubmitGroup"></asp:TextBox>
<asp:button id="Button2"
text="Validate"
causesvalidation="true"
validationgroup="SubmitGroup"
runat="Server" />
you will also have to write the ValidationGroup on DetailsView etc.
good luck`
Sincerely,
Mahad Bin Mukhtar Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
daisy1234
0 Points
1 Post
gridview and detailsview
Jun 03, 2012 01:38 AM|LINK
I have a detail view and gridview in one form. The user enter the information to the detailsview and then everything user entered will show in the gridview. The problem happen when I try to update the gridview, the validation control in the detailsview fired. If I take away the validation control in the detailsview, everyting work fine.
The question is how can I update the gridview by calling GridView1_RowUpdating and stop the validation control pops the error message from detailsview.
Protected Sub GridView1_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim lb As Label = DirectCast(GridView1.Rows(e.RowIndex).FindControl("Label6"), Label)
Dim chb As CheckBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("chkalarm"
), CheckBox)
Dim ddlone As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList3"), DropDownList)
Dim ddltwo As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList4"), DropDownList)
Dim tx1 As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("TextBox1"), TextBox)
Dim tx2 As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("TextBox2"), TextBox)
Dim sql As String = "UPDATE dbo.Alarm SET isenable= " & Convert.ToByte(chb.Checked) & ","_
&
"sip=" & tx1.Text & ", channel='" & ddlone.SelectedValue.ToString() & "', tofalam='" & ddltwo.SelectedValue.ToString() & "',alarmlimit=" & tx2.Text & " where alarmid="& Convert.ToDouble(lb.Text)
gd.ExecuteQuery(sql)
--------------------
the validation control in detailsview
<ContentTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="AddProductDataSource"
DefaultMode="Insert" DataKeyNames="ProductID" CellPadding="4" ForeColor="#333333" GridLines="None">
<Fields>
<asp:TemplateField HeaderText="Sip:">
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("zip") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="You must provide zip number"
SetFocusOnError="True" ControlToValidate="textbox1">*</asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Channel:">
<
MahadTECH
Star
8976 Points
1659 Posts
Re: gridview and detailsview
Jun 03, 2012 07:22 AM|LINK
Try these Links
good luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
MahadTECH
Star
8976 Points
1659 Posts
Re: gridview and detailsview
Jun 03, 2012 07:37 AM|LINK
you will have to Specify the Validation Group
http://msdn.microsoft.com/en-us/library/ms227424.aspx
The Controls you want to be validated write the Validation Group in there Markup
like
<asp:requiredfieldvalidator id="RequiredFieldValidator1" controltovalidate="NameTextBox" validationgroup="SubmitGroup" // Write this Same "SubmitGroup" To the Controls also on SubmitButton etc. errormessage="Enter your name." runat="Server"> </asp:requiredfieldvalidator> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("zip") %>' validationgroup="SubmitGroup"></asp:TextBox> <asp:button id="Button2" text="Validate" causesvalidation="true" validationgroup="SubmitGroup" runat="Server" /> you will also have to write the ValidationGroup on DetailsView etc.good luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: gridview and detailsview
Jun 03, 2012 08:29 AM|LINK
Hi try this
tx1.CausesValidation = False