Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C#
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.
Posted
Updated 22-Aug-13 23:40pm
v2
Comments
CodeBlack 23-Aug-13 5:19am    
can you upload your aspx code also ?
Aboobakkar Siddeq D U 23-Aug-13 5:23am    
public DataSet GetDataSet(string a_strDataSource)
{
if (_sConn.State != ConnectionState.Open)
{
_sConn.Open();
}
System.Data.SqlClient.SqlDataAdapter myAdapter;
DataSet DS;
try
{
DS = new DataSet();
myAdapter = new System.Data.SqlClient.SqlDataAdapter(a_strDataSource, _sConn);
myAdapter.SelectCommand.CommandTimeout = _connectionTimeout;
myAdapter.Fill(DS);
myAdapter.Dispose();
myAdapter = null;
return DS;
}
catch (Exception ex)
{
ex.Data.Clear();
return null;
}
finally
{
_sConn.Close();
}
}
Aboobakkar Siddeq D U 23-Aug-13 5:25am    
I'm using this inside Row_Command

protected void gvBlackAmount_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{

if (e.CommandName == "Update")
{
int customerId = int.Parse(e.CommandArgument.ToString());

Session["CustomerId"] = customerId;
//BindCustomerDetails(customerId);
//BindBalance(customerId);

string getVal = "select * from CustomerDetails where CustomerId=" + customerId;
DataSet ds = _bindDetails.GetDataSet(getVal);
if (ds.Tables[0].Rows.Count > 0)
{
txtCustomerName.Text = ds.Tables[0].Rows[0]["CustomerName"].ToString();
txtTotalValue.Text = ds.Tables[0].Rows[0]["TotalValue"].ToString();
txtAgreementValue.Text = ds.Tables[0].Rows[0]["AgreementValue"].ToString();
txtBalanceAmount.Text = (decimal.Parse(txtTotalValue.Text.ToString()) - decimal.Parse(txtAgreementValue.Text.ToString())).ToString();
}
}
}
catch (Exception ex)
{
ex.Data.Clear();
}
}
Dholakiya Ankit 23-Aug-13 5:42am    
by watch element you are getting value?
Dholakiya Ankit 23-Aug-13 5:43am    
asking for aspx code not cs

C#
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 
 
Share this answer
 
v2
you can use column index rather than column name in your coding .
like this ...
C#
txtCustomerName.Text = dr[1].ToString();
                 txtTotalValue.Text = dr[2].ToString();
 
Share this answer
 
v2
You can simply do this by
C#
txtCustomerName.Text=dt.Rows[0]["CustomerName"].ToString();

Regards..:)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900