我在GridView上的C#上有以下工作,名爲GridView1。它在我將它放入onSelectedIndexChanged時有效。Gridviewcell到文本框不能正常工作
HostTextbox.Text = GridView1.SelectedRow.Cells[0].Text;
但由於這回發到我要避免它,因爲我會做它的細胞[0]細胞[10]服務器。所以,我研究了Javascript。我搜索並找到了各種解決方案,這是迄今爲止我「半工作」的解決方案。
我的C#是這樣的:
int myRowIdx = 0; // class variable
protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondbclick", "sample('" + myRowIdx.ToString() + "')");
}
myRowIdx++;
}
在我的JavaScript我插入警報,告訴我問題出在哪裏happpens。它看起來像這樣:
function sample(rowIn) {
alert("A");
var gViewID = '<%= GridView1.ClientID %>';
alert("B");
var gView = getElementById(gViewID);
alert("C");
var gViewRow = gView.rows[rowIn];
alert("D");
var gViewRowColumn = gViewRow.cells[0];
alert("E");
var displayCell = gViewRowColumn.innerText;
alert("F");
alert(displayCell);
}
B是我看到的最後一個警報。我似乎無法弄清楚這一點。我仔細研究過它,但仍然沒有成功。請幫忙。
由於它的工作! 我之前對細胞[0]的意思是,我正在像你說的那樣先後這樣做(我只是沒有把它包括在我的問題中)。當我這樣做時,整個頁面重新加載,並且Gridview刷新約10,000條記錄。我想這是因爲C#代碼是服務器端發生的。使用客戶端Javascript是最好的。 再次感謝。 – GetRichSlow1 2011-01-11 16:35:26