Monday, March 12, 2012

how to Copy Item one Gridview to another gridview

I have Two gridview left side where i populate data from Database and other will be empty at 1st time my requirement is when click any item and click to add button it will remove from that cell and add in to second gridview

same thing happens through drag and drop system Drag from one gridview to another well but it will be helpfull how to remove and add one gridview to another can someone give me idea

bye take care
regards
vikrant

Check out these links

http://forums.asp.net/p/1169459/1955946.aspx

http://www.codeproject.com/KB/HTML/SelectMoveRowsFromTables.aspx

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

How to copy gridview cell values?

I have a gridview that displays item #'s and my users want to be able to highlight any number and copy it by either right clicking or ctrl + c. But for some reason the individual cells can't be highlighted by double clicking. And when dragging over text it highlights the entire table!

<asp:GridView BorderWidth=1px BorderColor=Black Borderstyle=Solid HeaderStyle-BackColor=Aquamarine runat=server style="z-index: 100; left: 9px; position: absolute; top: 106px" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ID="GridView1" AllowPaging="True" AllowSorting="True"> <Columns> <asp:BoundField DataField="itemNumber" HeaderText="#" SortExpression="itemNumber" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:BoundField DataField="FirstPayDate" HeaderText="First Pay Date" SortExpression="FirstPayDate" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:BoundField DataField="Screen" HeaderText="Screen" SortExpression="Screen" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:BoundField DataField="Problem" HeaderText="Problem" SortExpression="Problem" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:BoundField DataField="DateIn" HeaderText="Date in" SortExpression="DateIn" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" > <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col" ForeColor="#0000C0" /> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> </asp:BoundField> <asp:CommandField HeaderText="Action" SelectText="Fixed" ShowSelectButton="True"> <ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="Col"/> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" /> </asp:CommandField> </Columns> <PagerTemplate> Goto Page <asp:DropDownList ID="ddlPageSelector" OnSelectedIndexChanged="pageChange" runat="server" AutoPostBack="true"> </asp:DropDownList>  Total Errors: <asp:Label ID="lbl_Total" runat="server" Text="Label"></asp:Label> </PagerTemplate> <HeaderStyle BackColor="Aquamarine" /></asp:GridView>

Try using a TemplateField instead of the BoundField. Then use a span to display your info.

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

How to convert time format

Hi all,

I had query some time information from the database and use a dataset to bind to a GridView.

But unfortunately, the time that display on the GridView is not my desired choice.

It was display as "3/1/2007 10:06:27 PM".

Does anyone know how to convert it as "3/1/2007 22:06:27"?

Part of my code is as follow

pgDataAdapter.Fill(ds,

"Start Time");

Thanks

Hi bslim67,

You can use the DataFormatString property of the GridView column to format the datetime value.

Hope this helps.


Hi,

Hi,

I had tried this.

<asp:BoundFieldDataField="starttime"dataformatstring="{0:dd/MMM/yy}"

HeaderText

="Start Time"ReadOnly="True"SortExpression="starttime"/>

But when I run the program during runtime, it seems that it did not take effect.

It still show me the date and time though my dataformat is only on date.

Please help.

Thanks


Dear , friend:

You should set HtmlEncode=false in the markup of:BoundField

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance


Hi,

Thanks for your info. It's really a great help for me.

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

How to convert text in GridView col into a hyperlink?

Hi,

One of the fields in a GridView control contains a unc path to a local area network folder [eg:\\servername\foldername].

Each record in the GridView may have a path to a different folder.

I would like to be able to click on the path in the GridView and have the folder open - instead of having to copy the text into the Start | Run dialog box of my pc.

I've looked at converting the column into a hyperlink control [by making it a Templated control] & I've tried this code:

<Columns>
<asp:hyperlinkfield datatextfield="Path"
datanavigateurlformatstring="Path"/>
<asp:BoundField DataField="Path"
HeaderText="Online"
SortExpression="Path" />
</Columns>

. . . and I get an error because the app is trying to open a folder in the directory where the web site resides rather than the folder that is indicated in the path [Text] in the column.

I'm trying to figure out how to tell asp.net to open the folder indicated by the unc path in the field . . .Confused

I'd appreciate any help I can get.

Thanks!

Robin

What most likely is happening, is all links in a website by default are relative, so you end up with a link to something like this

http://localhost:12345:\\servername\path

Which obviously isnt going to work. You can fix it by prefixing it with something it recognizes as a file path, rather than a relative path.


Try replacing your <asp:HyperLink /> with this:

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:HyperLinkText="TextField"id="myHL"runat="server"

NavigateUrl='<%# "file:///" + DataBinder.Eval(Container.DataItem, "Path").ToString() %>'></asp:HyperLink>

</ItemTemplate>

</asp:TemplateField>

</Columns>

Thanks, Hans! That worked.

I have one more question, though. In the Text = "TextField" - I would like the text that displays be the actual path that is coming in from the database.

So - instead of TextField [hard-coded literal] in the GridView I'd like it to have something like this -\\ServerName\FolderName [what is in the field for each record].

How would I do that?

Robin


Text='<%# Databinder.Eval(Container.DataITem, "Path").tostring() %>'


Thanks, Bryan. Perfect! I tried playing around with that line of code from Hans . . .

Robin

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

How to convert strings yymmdd (example: 060120) into regular dates (example: 01/20/06)?

I just want to do this for displaying the data using a gridview. I am working with VB.NET.

The dates need to be saved as they are (strings = yymmdd. example: 060911) so I do not want to save how the are saved in the SQL database.

But I want to display them using the gridview in the standard date format ('mm/dd/yyyy' or 'mm/dd/yy') so I will need to convert them.


I would like to know which would be a nice way to accomplish this, thanks for any suggestions.

another thing i would like to know how to do is to convert another field from the same gridview from string: (example: '2295' into formated amounts (example: $22.95) I do not care wether they are numeric or strings, because I just want it for displaying the data in the gridview. But also these values are saved without the decimal point, for example 10099, should be converted to $100.99 or 150089 should become $1,500.89

Thanks for suggestions.

remember I do not want to change or save this data into the database, because it is supposed to be saved as it is. But I do want to be able to show the user the data in the appropiate format.

The thing is that I do not know how or where to write the code to tell the gridview to convert it how I want it.

This will convert your date to a DateTime object

DateTime.ParseExact("060708","yymmdd", System.Globalization.CultureInfo.CurrentCulture ,System.Globalization.DateTimeStyles.None)

You can handle the RowDataBound event find the label you are displaying it in and set it to something like

mylabel.Text = DateTime.ParseExact("060708","yymmdd", System.Globalization.CultureInfo.CurrentCulture ,System.Globalization.DateTimeStyles.None).ToString("mm/dd/yyy")


I need help doing the rowdatabound for doing that formating

Protected Sub GridView1_RowDataBound(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView1.RowDataBoundTry If e.Row.RowType = DataControlRowType.DataRowThen Dim DollarAmountAs Label =CType(e.Row.FindControl("Label"), Label)
'Here I want to format the current string.text attribute. (how can i do it?)End If Catch End Try End Sub

You can try the solution above;

dim temp as string= DollarAmount.Text

DollarAmount.Text = DateTime.ParseExact(temp,"yymmdd", System.Globalization.CultureInfo.CurrentCulture ,System.Globalization.DateTimeStyles.None).ToString("mm/dd/yyy")


Thanks,Big Smile

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

How to convert string to int n gridview colors?

1st question on vb how do i convert string to int?

2nd question

eg.

GridView1.BorderColor = Drawing.Color.Aqua

its set on vb script but what i want to know is how to make it use color codes for eg. GridView1.BorderColor = #FFFFFF

thank you

Answer 1:

You can use either

int myInt =Integer.Parse(myString)

or

Dim myIntAs IntegerIf Integer.TryParse(myString,out myIntThen Return IntegerElse Return 0End If

Answer 2,

Dim cAs System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("#F5F7F8")Dim strHtmlColorAs String = System.Drawing.ColorTranslator.ToHtml(c)

1) Have a look at the Cint, Convert.ToInt16, Integer.Parse or Integer.TryParse methods

2) System.Drawing.Color.FromName("#FFFFFF")

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

How to convert from UserId to UserName in GridView?

i am using membership, and my GridView are using by choosing ObjectDataSource , In my ObjectDataSource i am using UserId, but when show the GridView i want the UserId changer UserName.How to do it? For example my some code,

<asp:TemplateField HeaderText="UserId"><ItemTemplate><%#Eval("UserId")%></ItemTemplate></asp:TemplateField>

You could write method that calls

MembershipUser u =Membership.GetUser(userID);.

username = u.UserName

Then call it from the template with <%# (String) MyGetUserNameMethod(String userid) %>

(declare the function protected string MyGetUseNameMethod in your code behind class)


Dear Sir,

Sorry i still can not understand!


hi

try this

<asp:TemplateField> <ItemTemplate><%#Membership.GetUser(Eval("UserId")).UserName%> </ItemTemplate> </asp:TemplateField>

Dear Sir,

Still can not!


hi

just replace your code with the one i gave you

so delete your templateField column and put my code

man if you still dont understand ,

could you explain what is the things that makes you confused

thanks


Dear Sir,

Thank!!it working,Sorry Sir, maybe just now i am typing wrong, Now, i am no error, Finally Thank you Sir!!!

Labels: , , , , , , , ,

how to convert a row in gridview to my business class DialUpRow generated by dataSet desig

I have GridView with: objectdatasource="objectdatasource1"

Objectdatasource1 is linked to my BLL (business layer with a dataset designer genrating: DialUpRow as an item of my datatable: DialupUpDataTable

I want to convert the selected row to my class: DialUpRow

I get the selected row using: myGRidView.SelectedIndex

But I don t know how to convert the grid row to my DialUpRow in order to get intellisence of my row properies (calss properties in code behind)

DataItem property of the GridViewRow would give the dataitem bound to the GridView. Below is a sample code. In the code, I haven't done any error checking, please ensure you do in your code.

Dim row as GridViewRow = GridView1.Rows(GridView1.SelectedIndex)if row isnot nothing thenDim drow as DialUpRow =CType(row.DataItem, DialUpRow)endif

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: , , , , , , , , , , , , ,