如何在ASP.NET MVC 4中动态地将多行绑定到多文本框 [英] How to Bind Mutiple rows to a Multine Textbox dynamically in ASP.NET MVC 4

查看:175
本文介绍了如何在ASP.NET MVC 4中动态地将多行绑定到多文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨团队,



在我的表中我跟踪下面的Converasation







TableID QueryID回复

1 12发布的用户:查询



2 12管理员回复:AnySolution



13 12发布的用户:谢谢









上面的表是基于QueryID的动态,我要么使用linq,要么使用存储过程来表格



现在我想把这个表的三行绑定到一个文本框,作为三行多行。请告诉我怎么做。

解决方案

你好swap_90,



我已经通过了你的查询,在这里我有一个解决方案: -



假设您有如下对话类:

  public   class 对话
{
public int TableID { get ; set ; }
public int QueryID { get ; set ; }
public string 回复{ get ; set ; }
}





现在你把所有的对话作为这个类对象的列表。

这里我手动将查询中显示的所有测试值添加到列表中,但我们可以假设它们从数据库中检索并添加到列表中。

列表与LT;会话> lstConversations =  new 列表< conversation>(); 
lstConversations.Add( new Conversation(){TableID = 1 ,QueryID = 12 ,Replies = 发布的用户:查询} );
lstConversations.Add( new Conversation(){TableID = 2 ,QueryID = 12 ,Replies = 管理员回复:AnySolution} );
lstConversations.Add( new Conversation(){TableID = 13 ,QueryID = 12 ,Replies = 发布的用户:谢谢} ); < / 对话 > < / 对话 >





现在我们可以使用LINQ将所有回复值作为IEnumerable: -

 var 回复= 来自 r   lstConversations 
其中 r.QueryID == 12
塞莱ct r.Replies;





最后我们必须将这些回复作为多行文字放到多行文本框中,这可能是完成如下: -

  string  strReplies =  String .Join(  \ n,回复); 
txtMultiTest.Text = strReplies;







希望这对您有所帮助。


Hi team ,

In my Table i m tracking the Converasation as below



TableID QueryID Replies
1 12 User Posted:Queries

2 12 Admin Replied: AnySolution

13 12 User Posted: thanks




the table above is dynamic based on QueryID , I would either use linq or using stored procedure for the table

Now I Want to Bind the three Rows of this table , to a Textbox as three Rows of multline . Please let me know how to do this .

解决方案

Hi swap_90,

I have gone through your query and here i have one solution for you :-

Let say you have the Conversation class as below :

public class Conversation
    {
        public int TableID { get; set; }
        public int QueryID { get; set; }
        public string Replies { get; set; }
    }



Now you got all the conversations as a list of this class object.
Here i have added manually to the list all the test values displayed by you in the query but we can assume them to be retrieved from database and added to a list.

List<conversation> lstConversations = new List<conversation>();
            lstConversations.Add(new Conversation() { TableID = 1, QueryID = 12, Replies = "User Posted:Queries" });
            lstConversations.Add(new Conversation() { TableID = 2, QueryID = 12, Replies = "Admin Replied: AnySolution" });
            lstConversations.Add(new Conversation() { TableID = 13, QueryID = 12, Replies = "User Posted: thanks" });</conversation></conversation>



Now we can use LINQ to get all the replies values as IEnumerable :-

var replies = from r in lstConversations
                          where r.QueryID==12
                          select r.Replies;



At last we have to put these replies as multiline text to a Multiline textbox which can be done as below :-

string strReplies = String.Join("\n", replies);
            txtMultiTest.Text = strReplies;




Hope this will definitely of help to you.


这篇关于如何在ASP.NET MVC 4中动态地将多行绑定到多文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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