Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have one grid view..
i am using this grid view for enter the data...
at start i am show 3 row
in every row there are save button to save current row data in database..

I want to validate this textbox...

But problem is if i am using
server side validation so if i validate Textbox1 for only alphabate so its validate Textbox1 of all row..Becuase same textbox repeated in all row ...

How can i validate in javascript... if it is inside of gridview

Plse give any suggestion....
Posted

Hi,

I make some code for your requirement .Just try that If you interested then make some changes to that and use it.

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language ="javascript" >
        function f1(tid) {
            tid.innerText = ""
        }
 </script>
</head>
<body >
    <form id="form1" runat="server">
    <div>
        <asp:datalist id="DataList1" runat="server" xmlns:asp="#unknown">
            onitemcommand="DataList1_ItemCommand" 
            onitemdatabound="DataList1_ItemDataBound"  >
        <HeaderTemplate >  <table>
        </HeaderTemplate>
        <itemtemplate>
       
      
          <tr>
            <td>
                <asp:textbox id="TextBox1" runat="server"></asp:textbox>
            </td>
            <td>
                <asp:linkbutton id="LinkButton1" runat="server" commandname="save" commandargument="2">save</asp:linkbutton>
            </td>
          </tr>
        
        </itemtemplate>
        <footertemplate>
         </footertemplate></table>
        
        </asp:datalist>
    </div>
    </form>
</body>
</html>


The code behind file contains following code

C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<string> g = new List<string>();
            g.Add("hjghj");
            g.Add("hjghj");
            g.Add("hjghj");
            g.Add("hjghj");
            g.Add("hjghj");
            g.Add("hjghj");
            g.Add("hjghj");
            DataList1.DataSource = g;
            DataList1.DataBind();
        }
    }


    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "save")
        {

        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            TextBox  rdblist = (TextBox )e.Item.FindControl("TextBox1");
            LinkButton lblqid = (LinkButton)e.Item.FindControl("LinkButton1");
            lblqid.OnClientClick = "f1("+rdblist.ClientID +")";
        }
    }
</string></string>


Here you've to change some code according to your requirement.

I hope you understood What I write

All the Best
 
Share this answer
 
Delphi

 
Share this answer
 
Use like this inside of column tag in asp:gridview

Quote:
<asp:templatefield headertext="TIN No." itemstyle-horizontalalign="Center" xmlns:asp="#unknown">
<edititemtemplate>
<asp:textbox id="txttin" runat="server" text="<%#Eval("tin") %>" />

<itemtemplate>
<asp:label id="lbltin" runat="server" text="<%#Eval("tin") %>" />

<footertemplate>
<asp:textbox id="txttin" runat="server" />
<asp:requiredfieldvalidator id="rfvtin" runat="server">
ControlToValidate="txttin" Text="*" ValidationGroup="validaiton" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900