Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 .
Posted

1 solution

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 :
C#
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.
C#
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 :-
C#
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 :-
C#
string strReplies = String.Join("\n", replies);
            txtMultiTest.Text = strReplies;



Hope this will definitely of help to you.
 
Share this answer
 
Comments
swap_90 12-Nov-14 7:11am    
Hi Thanks For the reply , but how Could i Bind the string StrReplies in a View.cshtml

@Html.TextArea("txtMultiTest", null, new { @maxlength = "500", @rows = "7", id = "txtMultiTest", @name = "txtMultiTest})

Please reply
SRS(The Coder) 12-Nov-14 8:07am    
Here it seems like a strongly typed model binding approach you are following, so i think you have to make it structured with the newline character before binding to the particular field.

Do the same in BL layer of your project or simply in Controller.
swap_90 12-Nov-14 9:00am    
Hi thanks , It was nice solution it worked for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900