2014-03-19 115 views

回答

5

檢查了這一點...

var tbl = document.getElementById('Gridview1'); 

var tbl_row = tbl.rows[parseInt(RowIndex) + 1]; 

var tbl_Cell = tbl_row.cells[no of the cell]; 

var value= tbl_Cell.innerHTML.toString(); 

這裏no of the cell指示列數。

如果它是一個模板字段,你可以試試這個..

var value=document.getElementById('GridViewId_ColumnID_' + RowIndex).value; 
+0

其工作正常。但是我想在你的代碼中得到這個變量的值。這個怎麼做。 – user3264676

+0

變量'值'具有特殊單元格的值..它是模板表達式嗎? – Jameem

+0

是模板字段。警報(值); 警報(值);來了。 待定 我想獲得在這個ID的值,在我的情況下它的待定。 – user3264676

1

一個簡單的例子。

function myfunc { 
     var b=document.getElementById("GridView1"); 
     var c=document.getElementById("TextBox1"); 
     var d=document.getElementById("TextBox2"); 
     dd=dd+1; 
     c.value=document.getElementById("GridView1").rows[dd].cells[2].innerHTML; 
     d.value=document.getElementById("GridView1").rows[dd].cells[3].innerHTML; 
    } 

獲取電網的ID。然後你樹旁玩耍用rows[]cells[]

0

後面的代碼頁:

protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      e.Row.Attributes.Add("onclick", "callFunctions('" + e.Row.RowIndex + "')"); 

      // e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" + e.Row.RowIndex); 
      e.Row.ToolTip = "Click to select this row."; 
     } 
    } 

的Javascript:

<script type="text/javascript"> 
    function callFunctions(i) { 
     //alert('Welcome'); 
     if (window.opener != null && !window.opener.closed) { 
      var tbl = document.getElementById('GridView1'); 
      var tbl_row = tbl.rows[parseInt(i) + 1]; 
      var tbl_Cell = tbl_row.cells[0]; 
      var value = tbl_Cell.innerHTML.toString(); 
      var txtName = window.opener.document.getElementById("txtName"); 
      txtName.value = value; 
     } 
     window.close(); 
    } 

</script> 

如果發生EnableEventValidation誤差平均集它的EnableEventValidation =「false」。

相關問題