Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my gridview 4 row
every row have add button...

i want when i click on any add button... so i get that row number in javascript client side before submitting the form.. ...

how can it possible...

i am able to get this by
onclick
event...


but i want this by
OnClientClick
event..

Plse help me...
Posted

1 solution

Hi,

Here I write some code for getting selected row in data control in javascript

try this
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        function as(tid) {
            var str = new String();
            var g=tid.split('_');
            alert("selected Row index is :"+g[2]);
          
        }
    </script>
</head>
<body  > 
    <form id="form1" runat="server">
    <div>
    
        <asp:datalist id="DataList1" runat="server" width="70%" xmlns:asp="#unknown">
            onitemcommand="DataList1_ItemCommand">
          <HeaderTemplate >
            <table width="100%" align="center" border="1">
                     </HeaderTemplate>
          <itemtemplate>
                <tr>
                 <td>
                     <asp:button id="Button1" runat="server" text="Button" onclientclick="as(this.id)" />
                 </td>
          
               </tr>
          </itemtemplate>
          <footertemplate>
              </footertemplate></table>
          
        
    </div>
    </form>
</body>
</html>



The code behind file contains following code

C#
protected void Page_Load(object sender, EventArgs e)
{
    List<string> str = new List<string>();
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    str.Add("sdgfsdfsd");
    DataList1.DataSource = str;
    DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{

}


I hopw you understand what I said


All the Best
 
Share this answer
 
v3
Comments
dilip.aim11 23-Sep-11 4:55am    
Really thanks
Muralikrishna8811 23-Sep-11 5:45am    
your are welcome
mayur csharp G 24-Sep-11 4:21am    
Thankx it is very useful

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