0
我有以下問題,並且我不知道如何修復它。
我有一個grid view
其中一列是template field
(文本框)。網格視圖由8
行組成。我所做的是每次用戶在文本框中輸入數據時,我將總數放在最後一個文本框中(set enabled = false)。我通過某種方法在文本框中總結數據條目並在事件中調用它text changed
。但每當我在文本框中輸入一個數字,然後點擊Tab in the keyboard
或使用鼠標光標移動到下一個框時,我就失去了焦點,我必須再次將鼠標光標置於預期的文本框中。
我嘗試了以下方法來解決我的問題,但徒勞無功。
foreach (GridViewRow r in gv_Evaluation.Rows)
{
((RadTextBox)r.Cells[3].FindControl("txt_evaluateWeights")).Attributes.Add("blur", "calc()");
}
在我的頁面加載,這根本不起作用。
protected void txt_evaluateWeights_TextChanged(object sender, EventArgs e)
{
calc();
((TextBox)sender).Focus();
}
這樣,焦點返回到前一個文本框(我的意思是,我已經做了一個),文本框不是我想的焦點,輸入數據。
編輯:
我的計算方法:
private void calc()
{
float sum = 0;
for (int i = 0; i < 7; i++)
{
RadTextBox txt1 = (RadTextBox)gv_Evaluation.Rows[i].Cells[3].FindControl("txt_evaluateWeights");
int weight;
bool result = Int32.TryParse(txt1.Text, out weight);
if (result)
{
sum += weight;
}
}
double percentage;
percentage = Math.Round((sum/100) * 100, 2);
RadTextBox txt3 = (RadTextBox)gv_Evaluation.Rows[7].Cells[3].FindControl("txt_evaluateWeights");
txt3.Text = percentage.ToString();//string.Format("{0:0.0%}", percentage.ToString());
}
你能發佈你的'calc'功能呢? – naveen
好的............ –
您想回傳並計算服務器端的金額還是想在客戶端進行?另外,您是否考慮過啓用Paging並且某些行根本不存在於客戶端的問題? 「將總數放在最後一個文本框中」是什麼意思,最後一行是TextBox還是f.e.在頁腳? –