Hi nedash,
Please refer the below code and modify as per your requirement.
HTML
<div>
<div>
<input name="TxtSMS" type="text" id="Txtmatn" />
<br />
Character Count:- <span id="LbltedaCh"></span>
<br />
Number Of Messages:- <span id="Lblsend" class="MessageCount"></span>
<br />
Quantity:- <span id="LblQuantity" class="MessageCount"></span>
<br />
Sum:- <span id="Lblsum" class="Sun"></span>
</div>
<asp:HiddenField ID="hfCharacterCount" runat="server" />
<asp:HiddenField ID="hfTextBoxValue" runat="server" />
<asp:HiddenField ID="hfLblsum" runat="server" />
<asp:HiddenField ID="hfMessageCount" runat="server" />
<div>
<asp:GridView ID="gvNumber" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:Label ID="LblNumber" 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 />
<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="150px" Height="120px" runat="server" />
</td>
</tr>
</table>
</div>
</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 () {
var i = 0;
$('[id*=Txtmatn]').keydown(function (e) {
var ctrlKey = 67, vKey = 86;
if (e.keyCode != ctrlKey && e.keyCode != vKey) {
$('[id*=hfCharacterCount]').val($(this).val().length);
$('[id*=LbltedaCh]').html($('[id*=hfCharacterCount]').val());
$('[id*=hfTextBoxValue]').val($(this).val());
if ($(this).val().length % 70 == 0) {
i = $(this).val().length / 70;
i = i + 1;
$('[id*=Lblsum]').html(i * ($('[Id*=LblTshE]').html()));
$('[id*=hfLblsum]').val($("[id*=Lblsum]").html());
$('[id*=hfMessageCount]').val(i);
$('.MessageCount').html($('[id*=hfMessageCount]').val());
}
else {
if ($(this).val().length == 0) {
i = 0;
}
else {
i = $(this).val().length / 70;
i = i + 1;
i = parseInt(i);
}
$('[id*=hfMessageCount]').val(i);
$('.MessageCount').html($('[id*=hfMessageCount]').val());
}
}
});
$('[id*=Txtmatn]').keyup(function (e) {
var ctrlKey = 67, vKey = 86;
if (e.keyCode != ctrlKey && e.keyCode != vKey) {
$('[id*=hfCharacterCount]').val($(this).val().length);
$('[id*=LbltedaCh]').html($('[id*=hfCharacterCount]').val());
$('[id*=hfTextBoxValue]').val($(this).val());
if ($(this).val().length % 70 == 0) {
i = $(this).val().length / 70;
i = i + 1;
$('[id*=Lblsum]').html(i * ($('[Id*=LblTshE]').html()));
$('[id*=hfLblsum]').val($("[id*=Lblsum]").html());
$('[id*=hfMessageCount]').val(i);
$('.MessageCount').html($('[id*=hfMessageCount]').val());
}
else {
if ($(this).val().length == 0) {
i = 0;
}
else {
i = $(this).val().length / 70;
i = i + 1;
i = parseInt(i);
}
$('[id*=hfMessageCount]').val(i);
$('.MessageCount').html($('[id*=hfMessageCount]').val());
}
}
});
$("[id*=Txtmatn]").bind('paste', function (e) {
setTimeout(function () {
$('[id*=hfCharacterCount]').val($("[id*=Txtmatn]").val().length);
$('[id*=LbltedaCh]').html($('[id*=hfCharacterCount]').val());
$('[id*=hfTextBoxValue]').val($("[id*=Txtmatn]").val());
var msgCount = "";
if ($("[id*=Txtmatn]").val().length != 0) {
msgCount = $("[id*=Txtmatn]").val().length / 70;
msgCount = msgCount + 1;
}
else {
msgCount = 0;
}
$('[id*=Lblsum]').html(Math.floor(msgCount) * (Math.floor($('[Id*=LblTshE]').html())));
msgCount = Math.floor(msgCount);
$('[id*=hfLblsum]').val($("[id*=Lblsum]").html());
$('[id*=hfMessageCount]').val(msgCount);
$('.MessageCount').html($('[id*=hfMessageCount]').val());
}, 100);
});
});
</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("LblNumber") 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();
}
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("LblNumber"), 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
Screenshot