无法在文本框中查看数据 [英] Not able to view Data's on textbox

查看:90
本文介绍了无法在文本框中查看数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用datarow绑定来自datatable的文本框,我正在获取值,我可以分配给每个文本框。但在网页中我无法在文本框中看到这些值?请帮助解决这个问题我的代码是这样的。

 DataTable dt =  new  DataTable(); 
dt = _bindDetails.GetCustomerDetails(customerId);
if (dt.Rows.Count > 0
{
foreach (DataRow dr in dt .Rows)
{
txtCustomerName.Text = dr [ CustomerName]的ToString();
txtTotalValue.Text = dr [ TotalValue]。ToString();
txtAgreementValue.Text = dr [ AgreementValue]。ToString();
txtBalanceAmount.Text =( decimal .Parse(txtTotalValue.Text.ToString()) - decimal .Parse(txtAgreementValue.Text.ToString()))的ToString();
}
}



请帮助我。

解决方案

你已经使用了每个循环,但我认为你只有一次文本框... 尝试  for 循环并为数据表提供适当的索引,如

txtCustomerName.Text = dt.Rows [ 0 ] [ CustomerName]。ToString();

如果它有助于选择 as answer


你可以在你的编码中使用列索引而不是列名。

像这样...

 txtCustomerName.Text = dr [ 1 ]。ToString(); 
txtTotalValue.Text = dr [ 2 ]。ToString();


你可以简单地通过

 txtCustomerName.Text = dt.Rows [ 0 ] [  CustomerName]。ToString(); 



问候。 :)


I'm binding textboxes from datatable using datarow, i'm getting values and i can assign to each textbox. But in Webpage i can't see those values in textbox? Please help to solve this problem my code is like this.

DataTable dt = new DataTable();
            dt = _bindDetails.GetCustomerDetails(customerId);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    txtCustomerName.Text = dr["CustomerName"].ToString();
                    txtTotalValue.Text = dr["TotalValue"].ToString();
                    txtAgreementValue.Text = dr["AgreementValue"].ToString();
                    txtBalanceAmount.Text = (decimal.Parse(txtTotalValue.Text.ToString()) -    decimal.Parse(txtAgreementValue.Text.ToString())).ToString();
                }
            }


Please help me.

解决方案

you have use fore each loop but i think u have text box only once...try for loop and give proper index to datatable like

txtCustomerName.Text=dt.Rows[0]["CustomerName"].ToString();

if it helps select as answer 


you can use column index rather than column name in your coding .
like this ...

txtCustomerName.Text = dr[1].ToString();
                 txtTotalValue.Text = dr[2].ToString();


You can simply do this by

txtCustomerName.Text=dt.Rows[0]["CustomerName"].ToString();


Regards..:)


这篇关于无法在文本框中查看数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆