Javascript validation for gridview control

Posted by Dipu710646 under ASP.NET on 12/1/2012 | Points: 10 | Views : 14951 | Status : [Member] | Replies : 4
Hi All,

I have a gridview. I need to validate some text box before updating data (like can not be empty). It should be client side validation.

Is there anyway to do that ?

Any response is appreciated.

Thanks,
Dipankar




Responses

Posted by: Sourabh07 on: 12/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..

try this link....

you will be able to perform client side functionality.....in the gridview...

http://www.dotnetfunda.com/codes/code3530-checkbox-functionality-in-gridview-using-javascript.aspx



Sourabh07

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipu710646 on: 12/3/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply.

But my requirement is bit different. I want the textbox corresponding to the particular row which is being updated..

While clicking the update for that particular row, we need to validate the textbox of the corresponding row.

Thanks,
Dipankar

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manoj_B on: 12/4/2012 [Member] Starter | Points: 25

Up
0
Down
hiii,

Use this follwing code, it'll work fine.

<script language="javascript" type="text/javascript">


function Check() {


var counts = document.getElementById("gvDeatils").rows.length - 1;
var rows;


for (var i = 0; i < counts; i++)
{
if (i + 2 < 10) {
rows = "0" + (i + 2);
}
else {
rows = i + 2;
}
if (document.getElementById("gvDeatils_ctl" + rows + "_cbItem").checked == true) {

if(document.getElementById('gvDeatils_ctl' + rows + '_txtName').value="") {
alert("Please Enter Your Name !");
return false;
}
}

}
return true;
}
</script>

--------------------------------------------------------------------------------------------------

<asp:GridView ID="gvDeatils" runat="server" AutoGenerateColumns="False" EmptyDataText="No Record Found" Width="100%"

CellPadding="2" border="0">
<EmptyDataRowStyle ForeColor="#CC0000" />
<Columns>
<asp:TemplateField>

<HeaderTemplate>
<input id="Checkbox1" type="checkbox" name="Selchk"runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbItem" runat="server"></asp:CheckBox>
</ItemTemplate>

</asp:TemplateField>
<asp:BoundField HeaderText="Sl#"/>

<asp:TemplateField HeaderText="Full Name">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" AutoCompleteType="Disabled"></asp:TextBox>

</ItemTemplate>
</asp:TemplateField>


</Columns>

</asp:GridView>

<asp:Button runat="server"
Text="Submit" ID="btnSubmit" OnClientClick="return Check();"/>





Thanks & Regards
Manoj Kumar

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Siba_Sahoo on: 12/4/2012 [Member] Starter | Points: 25

Up
0
Down
Basically, gridview renders as tables.Take that textbox id for perticular row
do validation.

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response