Hi nedash,
I have created sample code which full-fill your requirement.
HTML
<div>
<asp:GridView ID="gvNumber" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:Label ID="Lblmobile" Text='<%#Eval("Number")%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnAdd" Text="Add" OnClick="LBaddNumber_Click" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button Text="Add All" runat="server" class="btnClass" OnClick="OnAddAll" />
<br />
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>
Number of count:<asp:Label ID="LblTshE" Text="" runat="server" />
</th>
</tr>
<tr>
<td>
<asp:TextBox ID="TxtPhone" TextMode="MultiLine" Width="180px" Height="150px" runat="server" />
</td>
</tr>
</table>
</div>
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=TxtPhone]').on("keyup", function () {
var numbers = $(this).val().split(/\n/g);
var count = 0;
for (var i = 0; i < numbers.length; i++) {
if (numbers[i].trim() != '') {
count++;
}
}
$('[Id*=LblTshE]').html(count);
});
});
</script>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Number", typeof(int));
dt.Rows.Add("25635863");
dt.Rows.Add("254635863");
dt.Rows.Add("256667863");
dt.Rows.Add("256377563");
gvNumber.DataSource = dt;
gvNumber.DataBind();
}
}
protected void LBaddNumber_Click(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string number = (row.FindControl("Lblmobile") as Label).Text.Trim();
if (!string.IsNullOrEmpty(TxtPhone.Text))
{
TxtPhone.Text = number.Trim() + Environment.NewLine + TxtPhone.Text;
}
else
{
TxtPhone.Text = number.Trim();
}
LblTshE.Text = (TxtPhone.Text.Split('\r').Length).ToString();
}
protected void OnAddAll(object sender, EventArgs e)
{
string numbers = string.Empty;
if (!string.IsNullOrEmpty(TxtPhone.Text))
{
numbers = TxtPhone.Text + Environment.NewLine;
foreach (GridViewRow row in gvNumber.Rows)
{
numbers += (row.FindControl("Lblmobile") as Label).Text.Trim() + Environment.NewLine;
}
TxtPhone.Text = numbers.Trim();
}
else
{
foreach (GridViewRow row in gvNumber.Rows)
{
numbers += (row.FindControl("Lblmobile") as Label).Text.Trim() + Environment.NewLine;
}
TxtPhone.Text = numbers.Trim();
}
CountMessage();
}
private void CountMessage()
{
LblTshE.Text = (TxtPhone.Text.Split('\r').Length).ToString();
}
Vb.net
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.Add("Number", GetType(Integer))
dt.Rows.Add("25635863")
dt.Rows.Add("254635863")
dt.Rows.Add("256667863")
dt.Rows.Add("256377563")
gvNumber.DataSource = dt
gvNumber.DataBind()
End If
End Sub
Protected Sub LBaddNumber_Click(sender As Object, e As EventArgs)
Dim row As GridViewRow = TryCast(TryCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim number As String = TryCast(row.FindControl("Lblmobile"), Label).Text.Trim()
If Not String.IsNullOrEmpty(TxtPhone.Text) Then
TxtPhone.Text = number.Trim() + Environment.NewLine + TxtPhone.Text
Else
TxtPhone.Text = number.Trim()
End If
LblTshE.Text = (TxtPhone.Text.Split(ControlChars.Cr).Length).ToString()
End Sub
Protected Sub OnAddAll(sender As Object, e As EventArgs)
Dim numbers As String = String.Empty
If Not String.IsNullOrEmpty(TxtPhone.Text) Then
numbers = TxtPhone.Text + Environment.NewLine
For Each row As GridViewRow In gvNumber.Rows
numbers += TryCast(row.FindControl("Lblmobile"), Label).Text.Trim() + Environment.NewLine
Next
TxtPhone.Text = numbers.Trim()
Else
For Each row As GridViewRow In gvNumber.Rows
numbers += TryCast(row.FindControl("Lblmobile"), Label).Text.Trim() + Environment.NewLine
Next
TxtPhone.Text = numbers.Trim()
End If
CountMessage()
End Sub
Private Sub CountMessage()
LblTshE.Text = (TxtPhone.Text.Split(ControlChars.Cr).Length).ToString()
End Sub
Screenshot