Here, we will see how to concatenate integers
and string in C#. To do that we take two TextBox for integers and one TextBox
for string and one TextBox for concatenate both integers and string.
Aspx code
<%@
Page Language="C#"
AutoEventWireup="true"
CodeBehind="add.aspx.cs"
Inherits="addtextbox.add"
%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
First:
<asp:TextBox
ID="txt1"
runat="server"></asp:TextBox>
<br
/>
<br
/>
Second:<asp:TextBox
ID="txt2"
runat="server"></asp:TextBox>
<br
/>
<br
/>
Third<asp:TextBox
ID="txt3"
runat="server"></asp:TextBox>
<br
/>
<br
/>
<asp:Button
ID="Button1"
runat="server"
onclick="Button1_Click"
style="margin-bottom:
0px" Text="Button"
/>
<br
/>
<br
/>
Fourth:<asp:TextBox
ID="txt4"
runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
The form looks like below figure1.
Figure1
Now double click on the Button control and add
the following code.
protected
void Button1_Click(object
sender, EventArgs e)
{
int a =Convert.ToInt32(txt1.Text)
;
int b= Convert.ToInt32(txt2.Text);
string c = txt3.Text;
txt4.Text =
a.ToString() + b.ToString() + c;
}
Now run the application and test it.
Figure2
Now click on the Button to Concatenate integers
and string.
Figure3