如何将gridview绑定到html表? [英] How to bind gridview to an html table?

查看:75
本文介绍了如何将gridview绑定到html表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我遇到了一个问题,我急需其解决方案.
在我的设计中,我有一个gridview和一个附加的sql数据源,此外,我还有一个html表.
html表有3行,每行有3列.每个单元格由文本框组成,即
第一行包含textbox1,textbox2,textbox3.同样,
第二行具有textbox4,textbox5,textbox6,与第三行textbox7、8、9 ...相同.
对于gridview,我在每行上都有一个选择的命令.
为了将数据从gridview绑定到html表的第一行,我们编写

Hello, I had encountered a problem, I desperately need its solution.
In my design, I have a gridview and an sql data source attached to it, along with that, I have an html table also.
html Table has 3 rows with each row having 3 columns. Each cell consists of textboxes i.e.,
First row has textbox1, textbox2, textbox3. In the same way,
Second row has textbox4, textbox5, textbox6 likewise the same in third row textbox7,8,9....
For gridview, i have a select ommand on each row.
For binding data from gridview to 1st row of html table, we write

TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[2].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[3].Text;


上面的代码很好用,但是之后如果我需要将数据绑定到表的第二行,该怎么办?


The above code works good but after that if I need to bind data to second row of the table, how should I do it?

推荐答案

int rowcount = 0;
int.TryParse(ViewState["rowcount"] + "", out rowcount);

if (rowcount == 0)
{
    rowcount++;
    ViewState["rowcount"] = rowcount;
    TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
    TextBox2.Text = GridView1.SelectedRow.Cells[2].Text;
    TextBox3.Text = GridView1.SelectedRow.Cells[3].Text;
}
else if (rowcount == 1)
{
    rowcount++;
    ViewState["rowcount"] = rowcount;
    TextBox4.Text = GridView1.SelectedRow.Cells[1].Text;
    TextBox5.Text = GridView1.SelectedRow.Cells[2].Text;
    TextBox6.Text = GridView1.SelectedRow.Cells[3].Text;
}
else if (rowcount == 2)
{
    rowcount++;
    ViewState["rowcount"] = rowcount;
    TextBox7.Text = GridView1.SelectedRow.Cells[1].Text;
    TextBox8.Text = GridView1.SelectedRow.Cells[2].Text;
    TextBox9.Text = GridView1.SelectedRow.Cells[3].Text;
}


这篇关于如何将gridview绑定到html表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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