How to copy the data in textboxes

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1623
hi
check this code



protected void Bt_Submit_Click(object sender, EventArgs e)
{
Txt2.Text = Txt1.Text;
int ItemsCnt = DrpList.Items.Count;

for (int i = 0; i <= ItemsCnt-1; i++)
{
DropDownList1.Items.Add(DrpList.Items[i].Text);
}

}

<form id="form1" runat="server">
<asp:TextBox ID="Txt1" runat ="server" ></asp:TextBox>
<asp:DropDownList ID="DrpList" runat ="server" >
<asp:ListItem Text ="Asp.net" Value ="0">Asp.net</asp:ListItem>
<asp:ListItem Text ="Vb.net" Value ="1">Vb.net</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Bt_Submit" runat ="server" Text ="Copy Data"
onclick="Bt_Submit_Click" />
<asp:TextBox ID="Txt2" runat ="server" ></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat ="server">
</asp:DropDownList>
</form>

Comments or Responses

Posted by: Satyapriyanayak on: 9/18/2013 Level:Silver | Status: [Member] [MVP] | Points: 10
DrpList.Items.Text

Error 1 'System.Web.UI.WebControls.ListItemCollection' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Web.UI.WebControls.ListItemCollection' could be found

Posted by: Jayakumars on: 9/18/2013 Level:Bronze | Status: [Member] [MVP] | Points: 10
hi
sathyapriyanayak

put this index -> i
DropDownList1.Items.Add(DrpList.Items[i].Text);
Posted by: Allemahesh on: 9/18/2013 Level:Silver | Status: [Member] [MVP] | Points: 10
You can use the blow code:-

foreach (ListItem li in DrpList.Items)
{
DropDownList1.Items.Add(li);
}

Login to post response