且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过onclienclick事件获取gridview的选定行

更新时间:2023-12-05 10:36:34



在这里,我编写了一些代码来获取javascript中数据控件中的选定行

试试这个
Hi,

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

try this
<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

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