Monday, March 12, 2012

How to copy the content of a textbox with a button click?

Hi, i use Visual Web Developer 2005 express with Visual Basic and asp.net. I have a formView with a textbox and a button, i want to be able to copy the content of the textbox clicking on the button to paste the content in somewhere else.

Any one can help me with the code?

<asp:FormView ID="FormView1" runat="server" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="Both">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<ItemTemplate>
<table style="width: 561px; height: 85px" border="1" bordercolor="gainsboro">
<tr>
<td style="width: 156px; text-align: left;">
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
Text="Test:"></asp:Label></td>
<td style="width: 302px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ed_order_number", "{0}") %>'
Width="250px"></asp:TextBox></td>
<td style="width: 54px; text-align: center;">
<asp:Button ID="Button1" runat="server" Text="Copy" OnClick="Button1_Click" /></td>
</tr>

</table>
</ItemTemplate>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderTemplate>
<table style="width: 401px; height: 67px">
<tr>
<td colspan="3" rowspan="3" style="height: 34px">
<asp:Label ID="Label37" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Medium"
Text="Order Details"></asp:Label></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</HeaderTemplate>
</asp:FormView>

Are you looking for something like this?

protected void Button1_Click(object sender, EventArgs e){TextBox TextBox1 = FormView1.FindControl("TextBox1")as TextBox;if (TextBox1 ==null) {return; }string value = TextBox1.Text;// Do what you want with value here}

I need to simulate the Ctrl + C function on the button to copy the content of the textbox, and after paste it in somewhere else.


bonfa:

Hi, i use Visual Web Developer 2005 express with Visual Basic and asp.net. I have a formView with a textbox and a button, i want to be able to copy the content of the textbox clicking on the button to paste the content in somewhere else.

Any one can help me with the code?

Hi there,

Have a look at this forum with a working examplehttp://forums.asp.net/t/1047507.aspx


I use Visual basic not C Sharp.


The code is all Javascript thoughWink

Labels: , , , , , , , , , , , ,

How to copy n paste .asp files to Solution Explorer and have it show up there?

Hi,
I have just installed Visual Studio.net 2003 Enterprise Architect.
I have been using Visual Interdev so far, and I am used to be able to select
from a desktop, drag bunch of .asp files, and drop them into a Project
Explorer window and have it show there as a tree of files. Is there some
setting that I need to enable in Visual Studio.Net to do the drag and drop
to Solution Explorer (which seems to be the equivalent of Project Explorer
in InterDev) and have it show there as a tree of files?
Thank you for your help.Drop into the folder in Windows Explore, show all files and then include in
project is one option.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
*************************************************
Think outside the box!
*************************************************
"Jason Robertson" <jason6869@.msn.com> wrote in message
news:Y9udnQFGsI3wN-fcRVn-pA@.comcast.com...
> Hi,
> I have just installed Visual Studio.net 2003 Enterprise Architect.
> I have been using Visual Interdev so far, and I am used to be able to
> select
> from a desktop, drag bunch of .asp files, and drop them into a Project
> Explorer window and have it show there as a tree of files. Is there some
> setting that I need to enable in Visual Studio.Net to do the drag and drop
> to Solution Explorer (which seems to be the equivalent of Project Explorer
> in InterDev) and have it show there as a tree of files?
> Thank you for your help.
>

Labels: , , , , , , , , , , , , , ,

How to convert a GridView Column into Hyperlink fields?

I am trying to display records from an SQL database using an ASP.Net GridView control but I would like for one of the columns to be a Hyperlink or Hyperlink fields. Im using a DataTable to get the info from the DB.
For example:

protected void Page_Load(object sender, EventArgs e)
{
string queryString = "SELECT * FROM Candidates";
connection.SelectQuery = queryString;
myTable = connection.get_Connection();//recive the data as DataTable
//
//May be something here to convert a specific column to an hyperlink.
//
GridView1.DataSource = myTable;
GridView1.DataBind();
myTable.Dispose();
}

You can convert the BoundField to a TemplateField:

For example:

<asp:TemplateFieldHeaderText="colName"><ItemTemplate><asp:HyperLinkrunat="server"ID="HyperLink2"NavigateUrl='<%# "mypage.aspx?Sample_ID=" & Eval("Sample_ID")& "&Count_ID=" & Eval("Count_ID")%>'Text='<%# Eval("colName")%>'></asp:HyperLink></ItemTemplate></asp:TemplateField>

You can also use a HyperLinkField. The DataTextField property is what is displayed. The DataNavigateUrlFields property is for anything you might need to add to the DataNavigateUrlFormatString property.

<asp:HyperLinkFieldDataTextField="ColumnName"DataNavigateUrlFields="ColumnName2"DataNavigateUrlFormatString="~/mypage.aspx?UserID={0}"HeaderText="Name"></asp:HyperLinkField>

Thank you maspr, I tryed it before and it creates a new column just like the one that I want to convert to hyperlinks, and actually it works but I dont want to show two columns (one regular and the same one like hyperlinks). Do you know a way to hide or make invisible the regular one?

thanks so much for your help.


Thanks Limno I just tryed that right now. The problem is that if i want to add the<asp:TemplateField> and then the hyperlink inside of it, first I need to create a <column> </column> tag on the GridView, but if I create a column, there will be two identical columns but one of them will be hyperlink and the other not. Maybe the conversion must be on the .cs file, to force the DataColum or the cell to be hyperlinks.
Actually, it is a very easy job to do. From the samrt tag, you use the Edit columns, Highlight the column you want to convert, and you can see there is a link on the right side says: "Convert this field into TemplateField". Click on it and put the code i showed you. You can play with it to make it fit your need. By the way, the TemplateField is very useful, you will need it from time to time for formating you databound controls (gridview, detailsview...). Let me know if I can help more. Thanks.

You can do it in the rowdatabound event of gridview if you like.

If e.Row.RowType = DataControlRowType.DataRowThen
Dim hlAsNew HyperLink
hl.NavigateUrl = "yoururl"
hl.Text = e.Row.Cells(indexOfYourColumn).Text
hl.Target ="daview" 'target frame for url
e.Row.Cells(indexOfYourColumn).Controls.Add(hl)

end if


But limno my GridView doesn't know which table it will recive because it is been fill dinamically by one Class that I create to make the connection and a method there return tha table as DataTable. So I cant use the Edit column to converti it. My DataBase isn't inside the project, I connect to it using a connection string which is hide on my connection class. This is why I think that the code must be on the C# files and not on the aspx ones. Any suggestions will be welcome.

P.S. I will post next the connection class and the code which recive the table.

Thanks a lot to all
Neozaid

This example do the connection to an access DB, I will change it later for the SQL one.

//This is my default.cs file
public partialclass _Default : System.Web.UI.Page
{
private Connection connection =new Connection();
private SortClass sorting =new SortClass();
private DataTable myTable;
private GridViewSortEventArgs column;

public _Default()
{
myTable =null;
}

protected void Page_Load(object sender, EventArgs e)
{
string queryString ="SELECT FirstName ... FROM Candidates";
connection.SelectQuery = queryString;
myTable = connection.get_Connection();//DataTable
GridViewCandidates.DataSource = myTable;
GridViewCandidates.DataBind();
myTable.Dispose();
}
}

////////////////////////////The next is the connection class/////////////////////////////////////

using System.Data.OleDb;public class Connection{private string selectQueryString;private OleDbDataReader readerDataReader;private OleDbCommand commandCommand =new OleDbCommand();private DataTable myDataTable;public Connection()//initialize the query string { selectQueryString =""; }//Here the class get or set the query to look on the DB. //If it don't have any query it will use the default one "".public string SelectQuery {get {return selectQueryString; }set { selectQueryString =value; } }//Method: make the connection to DB, & return the desired table.public DataTable get_Connection() {string connectionString ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\DB.mdb;"; OleDbConnection connConnection =new OleDbConnection(); connConnection.ConnectionString = connectionString; commandCommand.CommandText = SelectQuery; commandCommand.CommandType = CommandType.Text; commandCommand.Connection = connConnection; commandCommand.Connection.Open(); readerDataReader = commandCommand.ExecuteReader(CommandBehavior.CloseConnection); myDataTable =new DataTable(); myDataTable.Load(readerDataReader);//Dispose the objects. myDataTable.Dispose(); commandCommand.Dispose(); connConnection.Dispose();return myDataTable; }}
Sincerely,
Neozaid

Labels: , , , , , , , , , , , , ,