选择一行后,我需要GridView的多行显示在单个TextBox中。我可以选择一行并将其显示在TextBox中,这是它的代码:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
txtConfirm.Text = "Course: " + GridView1.SelectedRow.Cells[0].Text;
}
}
有人可以帮助我如何继续选择文本框的行吗?
答案 0 :(得分:0)
我只是在做这项工作...所以可能需要花点时间。记下需要寻址的特殊字符。
public string GridtoCVS(GridView gvParm)
{
StringBuilder sbRetVal = new StringBuilder();
for (int i = 0; i <= gvParm.Rows.Count - 1; i++)
{
StringBuilder sbLine = new StringBuilder();
for (int j = 0; j <= gvParm.Columns.Count - 1; j++)
{
sbLine.Append(gvParm.Rows[i].Cells[j].Text.Trim() + ",");
}
string sLine = sbLine.ToString().Replace(" ", "").Replace("'","'").Replace("&","&");
sbRetVal.AppendLine(sLine);
}
return sbRetVal.ToString();
}
答案 1 :(得分:0)
选择所有行:您可以选择从foreach
行而不是SelectedRow
行中获取所有行数据,如下所示:
String AllRows = String.Empty; // add all rows in this String variable
// Iterate to all rows of your gridview
foreach (GridViewRow row in GridView1.Rows)
AllRows += "Course: " + row.Cells[0].Text + "\n"; Add Current row the String
txtConfirm.Text = AllRows; // set String variable to the TextBox
持久化TextBox数据:您可以像这样持久存储TextBox中的前几行数据:
String AllRows = txtConfirm.Text; // add TextBox data in this String variable
// Iterate to all rows of your gridview
foreach (GridViewRow row in GridView1.Rows)
AllRows += "Course: " + GridView1.SelectedRow.Cells[0].Text; + "\n";
txtConfirm.Text = AllRows; // set String variable to the TextBox