且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在gridview seprate行中添加多行文本框值

更新时间:2023-12-04 13:10:16

你可以拆分多行的值文本框,然后将每个部分添加为一行。

[更新]添加评论代码

 DataTable dt =  new  DataTable(); 
dt.Columns.Add( ABCD typeof string ));

string parts [] = textBox1.Split( new char [] {' \ r'' \ n'},StringSplitOptions.RemoveEmptyEntries);
foreach string part in 部分)
{
// 通过更新网格视图中的每一部分作为一行添加数据表
dt.Rows.Add(部分);
}


我希望对你有所帮助。


请尝试解决方案








 <   asp:TextBox   

ID = TextBox7 runat = server AutoPostBack = true

OnTextChanged = TextBox7_TextChanged 高度 = 23px 宽度 = 151px TextMode = MultiLine > < / asp:TextBox &GT; 跨度>


hi,
I create one application in that gridview with one column name Testname and one multi line text box and submit button.

I want to add multi line textbox value in Gridview seprate rows.
suppose I type 2 line in multi line textbox
hi
hello

after click on submit button I want following output in gridview

Testname
hi
hello

want each line of textbox in each row of gridview

You can split the value of the multi-line textbox and then add each part as one row.
[UPDATE] Added code from comment
DataTable dt = new DataTable();
dt.Columns.Add("ABCD", typeof(string));

string parts[] = textBox1.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string part in parts)
{
    // Add each part as a row in the gridview via updating the datatable
    dt.Rows.Add(part);
}


i hope its help for u

pls try to solution




<asp:TextBox

                  ID="TextBox7" runat="server" AutoPostBack="true"

                  OnTextChanged="TextBox7_TextChanged" Height="23px" Width="151px" TextMode="MultiLine" ></asp:TextBox>