Hi,
I want to store one by one data dynamically in DetailsView from DataTable and display result in DetailsView.
After Store data into database table then display.
Suppose, Table attribute of "Product" table are
1. ID (Int) (Auto Increment)
2. Features (Varchar2(50))
I want to store "Product name", "Color" and "Price" into only one column i.e, "Features";
protected void Button1_Click(object sender, EventArgs e)
{
string item1 = TextBox1.Text + "\n";
string item2 = TextBox2.Text + "\n";
string item3 = TextBox3.Text + "\n";
string AllItem = item1 + item2 + item3;
con.Open();
cmd.Connection = con;
cmd.CommandText = "insert into product values('" + AllItem + "')";
cmd.ExecuteNonQuery();
con.Close();
}
Then I try to store value separately into DataTable Then display DetailsView:
protected void Button2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
con.Open();
cmd.Connection = con;
cmd.CommandText = "Select Features from Product where id=5";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string result = dr["Features"].ToString();
int ln = result.Length;
dt.Columns.Add("items");
int index = result.IndexOf("\n");
while (ln > 0)
{
string a = result.Substring(0, index);
dt.Rows.Add(a);
ln = ln - (index + 1);
result = result.Substring(index + 1, ln);
index = result.IndexOf("\n");
}
}
int len = dt.Rows.Count;
for (int i = 0; i < len; i++)
{
DetailsView1.Rows.Cells.Text = dt.Rows[1].ToString();
}
DetailsView1.DataBind();
}
}
Store value in DataTable dt. That is
dt.Rows[0][0]=Nokia 5230
dt.Rows[1][0]-Black
dt.Rows[2][0]=7500
I want to store these value in following structure in DetailsView
Product Name: Nokia 5230
Color: Black
Price: 7500
But can't be store.
Please solve my problem.