Unable To Apply Dataformat String To Bound Columns Of Datagrid Generated Dynamically
Jan 17, 2011
following is sample code i am trying to make work. i want to apply formatting to datagrid column "price" i want price to be shown in currency format
Dim bColumn As BoundColumn
bColumn = New BoundColumn
bColumn.HeaderText = "name"
bColumn.DataField = "name"
dgBizDocs.Columns.Add(bColumn)
bColumn = New BoundColumn
bColumn.HeaderText = "price"
bColumn.DataField = "price"
bColumn.DataFormatString = "{0:C}" ' already tried following "{0:#,##0.00}"
dgBizDocs.Columns.Add(bColumn)
Dim dt As New DataTable
dt.Columns.Add("name")
dt.Columns.Add("price")
Dim dr As DataRow
dr = dt.NewRow
dr("name") = "ABC"
dr("price") = 1232100.53
dt.Rows.Add(dr)
dr = dt.NewRow
dr("name") = "ABC"
dr("price") = 123123.32
dt.Rows.Add(dr)
dt.AcceptChanges()
dgBizDocs.DataSource = dt
dgBizDocs.DataBind()
what am i doing wrong ?
View 2 Replies
Similar Messages:
Mar 28, 2011
why my dataformat string is not working. Below is the code I am using
<asp:BoundField HeaderText="Log Date" DataField="Log_Date" DataFormatString="{0:dd/MM/yy HH:mm}" ItemStyle-Font-Names="Arial" ItemStyle-Font-Size="13px" ItemStyle-HorizontalAlign="Right" HtmlEncode="false"/>
I need this in around 6 to 7 places. When I changed it everywhere to the same as above, it worked in only 2 places but others are not working. Its the same but dont know whats the reason.
View 5 Replies
Jul 27, 2010
I am using autogeneratecolumns ="false" and using some template fields.
It works when I use:
tempColumnNew = Me.DataGrid.Columns(oldColIndex)
tempColumnOld = Me.DataGrid.Columns(newColIndex)
Me.DataGrid.Columns.RemoveAt(oldColIndex)
Me.DataGrid.Columns.RemoveAt(newColIndex)
Me.DataGrid.Columns.AddAt(oldColIndex, tempColumnOld)
Me.DataGrid.Columns.AddAt(newColIndex, tempColumnNew)
But it doesnt remember the added columns on postback, so I have to add them for every postback.
Is there a better way to implement it?
View 2 Replies
Sep 30, 2010
I have "Order" object with Columns Ticket,OTP and CustomerName etc.Intially on DataGrid, I'm binding Ticket only , when user clicks on "Column Chooser" button, another windows appears to pickup CustomerName,OTP columns to add specified column dynamically on Datagrid. Environment : Asp.net ,C# with Object Data source
Public Class Order
{
publc void Order()
{
}
public string Ticket
{
get
{
return this.strTicket;
}
set
{
this.strTicket = value;
}
}
public string OtpNumber
{
get
{
return this.strOtpNumber;
}
set
{
this.strOtpNumber = value;
}
}
public string CustomerName
{
get
{
return this.strCustomer;
}
set
{
this.strCustomer = value;
}
}
}
}
View 1 Replies
May 27, 2010
I need to access the controls dynamically created template fields at run time in datagrid in post back event. Is there any way to retrieve the values in post back event? Or else give the ideas to acheive my requirement. I need to create no of rows and columns as text box as per user input. After fill the values to text box , i need to access the values in submit button.
View 1 Replies
Jul 20, 2010
I have a grid. I am building and populating it dynamically in C#. Below mentioned is my issue:
string s1 = "string1";
string s2 = "string2";
And then I have a header cell text which needs to be populated like this.
headercell.text = s1 + new string(' ', 20) + s2;
I am not able to get the extra 20 spaces between s1 and s2. It gives me just one space instead of 20 spaces.
I tried using headercell.text = s1 + s2.padleft(' ', 30); even then I am not able to get more than one space between strings s1 and s2.
View 9 Replies
Jan 19, 2010
GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();
But Grid is ok I can do
for (int i = 0; i < GridView1.HeaderRow.Cells.Count;i++)
I rename request headers here but
GridView1.Columns[i].Visible = false;
I can't use it because of GridView1.Columns.Count is 0. So how can I hide them ?
View 5 Replies
Dec 29, 2010
I have a datagrid with a text footer, and wanted to change the text in this footer when change selection in dropdownlist, but this change is not visible on the client(browser). I've been doing some tests and if i use the databinding() method datagrid is updated, and the text is correct.
My question is how to force the table to be drawn with the new changes. I think what the databinding() method is redrawing the datagrid, in the browser.
View 1 Replies
Feb 18, 2011
I want to find out the bound datarow or datatable of a datagrid on postback. I have a ButtonColumn in the grid. On click of the button, I'm trying to determine the datarow so that I can access the primary key and pass it to another page. The primary key is not bound and therefore not visible in the row.
For example I have a list of Customers, with an edit button. On clicking of the edit button, I want to open CustomerEdit.aspx?id=10. I am able to trap the click event on the server side in the DataGridCustomer_ItemCommand event. But am not able to get access to the datarow of the e.Item.ItemIndex.
On postback I'm NOT binding the datagrid. On accessing DataGridCustomer.DataSource, I get "Nothing". Is there a way to get the DataSource or the Datarow?
View 1 Replies
Aug 18, 2010
Background: I'm populating lots of asp.net c# GridViews and ListViews from a database and subsequently users may export them to Excel. I want export as native Excel (not html). I can't use office automation, and I'm using JET which works fine. I have no control over users' machines. Question: When doing the export, you have to tell Jet what type each field is, in my case "text" (varchar) or "numeric" (double). The difference is that if you export a numeric column, the users can sum the data in Excel, where as strings are exported with a leading apostrophe and so are not much use in arithmetic.
Currently I parse the first data row of the Grid/ListView, check if each value is numeric or text, and assign a type to the column accordingly. That works, except for when I have something in the first column which looks numeric but in fact is a text string. I don't want to parse every row in order to be sure I have the correct data type as some of these exports are quite large. When I load the Grid/ListView from the database, the database certainly knows what type each field is. So my question is... how do I extract the type of the database item behind a a Grid/ListView item? I could explicitly code it as an attribute on the item, but that's duplicating information I already have, if only I can get to it. I know that where I have a DataTable then I can get the underlying type from that, but mostly I don't have tables handy, just the Grid/ListView. Note that Jet will throw if you try to insert an empty string into a nullable numeric column. The way to do this is to omit that column name from the insert statement, or output a zero.
View 2 Replies
Oct 29, 2010
I have created gridview with list daatsource. I want apply sorting event for gridview to sort all columns.Here is my code:
protected void grduAdminSerservice_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable tbl = grduAdminSerservice.DataSource as DataTable;
[code]...
View 1 Replies
Mar 31, 2010
how can i set ID to tabelrows generated by datagrid/datalist i want to assign a row id by myself to every row of datalist.
View 1 Replies
Apr 14, 2010
I have got a simple gridview two bound columns and one template column with a textbox.
I need to get the values of the bound columns is this possible. I need to times the textbox with the bound column value
Now i can get the textbox value using
// var sumInput = null;
// var tempValue = 0.0;
// var retail = 0.0;
// function Load(sender, args) {
// sumInput = sender;
// }
// function Blur(sender, args) {
// sumInput.set_value(tempValue + (sender.get_value()));
// }
// function Focus(sender, args) {
// tempValue = sumInput.get_value() - (sender.get_value());
// }
View 4 Replies
Oct 24, 2011
I've got a grid view on my form that is bound to a data table at run tim. The data table is returned by a function rather than direct from the DB so I can't set the datasource at runtime.
I bind the grid in the page_load event like this:-
Code:
Dim _dt As System.Data.DataTable
_dt = _srvc.GetVinylShutters(0)
_dt.Rows.Add(_dt.NewRow)
grdShutters.DataSource = _dt
grdShutters.DataBind()
(_dt.Rows.Add(_dt.NewRow) is just there to add a blank row in, otherwise I wasn't seeing any columns at all)
I've then got the following snippet which I want to use to hide some underlying columns:-
Code:
For Each col As DataControlField In grdShutters.Columns
Select Case col.HeaderText
Case "OrderID", _
"ShutterID", _
"ModelID", _
[Code] ...
The thing is, wherever I put this it doesn't seem to hide the columns. If I break into the code I can see that grdShutters.Columns.Count equals zero althought I can see that the bound datatable has 38 columns.
I've tried the Page's Load, LoadComplete and PreRenderComplete events as well as the gridview's DataBound, RowDataBound and RowCreated events. I get teh same result in all of them. The grid doesn't actually have any columns until it appears on the screen.
View 7 Replies
May 25, 2010
I have a column, description, in a GridView which has the most text data. As that column is defined as varchar(256), it can allow a string with 256 characters in it. In displaying, I don't want that column to stretch all the way. I use ItemStyle-Width to contain it to be 40% width. I also use word-break and word-wrap as:
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
I guess this attribute apply to the whole GridView1. I have a column called category with possible data as "LINKAGE", "CURTAIN", etc. Now "LINKAGE" is broken up into "LINKAG" and "E" with the "E" goes to next line. The word "CURTAIN" have the "IN" goes to the next line.
Now how can I apply the word-break and word-wrap to only the description column?
View 3 Replies
Nov 8, 2010
I have a gridview with several ItemTemplates. The first contains a checkbox the rest contain textboxes. I then added dynamically some bound controls like this:
BoundField bdfPrivName = new BoundField();
clsUtilities.SetBoundFieldCenter(ref bdfPrivName, "PrivName", "Priv Name");
BoundField bdfDescription = new BoundField();
clsUtilities.SetBoundFieldLeft(ref bdfDescription, "PrivDesc", "Description");
BoundField bdfLive = new BoundField();
clsUtilities.SetBoundFieldCenter(ref bdfLive, "Live","Active?");
grdExisting.Columns.Add(bdfPrivName);
grdExisting.Columns.Add(bdfDescription);
grdExisting.Columns.Add(bdfLive);
I then use FindControl() to locate the checkbox and textboxes and perform my logic based the result
foreach (GridViewRow gvr in grdMissing.Rows) {
mckbAny = (CheckBox)gvr.FindControl("ckbAdd");
mtxtApplyDate = (TextBox)gvr.FindControl("txtAddApplyDate");
mtxtDateToAdd = (TextBox)gvr.FindControl("txtAddDateToAdd");
mtxtDateToRemove = (TextBox)gvr.FindControl("txtAddDateToRemove");
}
etc.
This all worked fine. I then got a request to put the bound fields as the second, third and fourth columns, after the check box and before the textboxes. I found that this was easy to do by changing the Add's to Inserts as follows:
grdExisting.Columns.Insert(1, bdfPrivName);
grdExisting.Columns.Insert(2, bdfDescription);
grdExisting.Columns.Insert(3, bdfLive);
It looked fine of the page, but the FindControl(), all of them fail to work.
View 2 Replies
Sep 6, 2010
I would like to make the datagrid bound column to hyperlink for redirecting to the details page .
For example , when my mouse over certain row of bound column in datagrid , it will change the colour to blue . Also , I can click it and redirect to the detail page .
Notes : I don't wan to use hyperlink column
View 7 Replies
Jan 24, 2010
I have a situation where I currently have a HyperLinkColumn control that I would like to modify to have a Label or simple text appear in the same column as the hyperlink. I tried setting this in the ItemCreated event but encountered the following error message
View 3 Replies
Jan 14, 2011
I have a DataTable where the columns are generated programmatically at runtime. I then bind this DataTable to a GridView. What I'm wondering is how I can create the GridView to accommodate this, and if it's not possible, how I can output the DataTable into nicely formatted HTML.
View 3 Replies
Sep 15, 2010
I would like to make the datagrid bound column to redirecting to the details page .
For example , when my mouse over certain row of bound column in datagrid , it will change the colour to blue . Also , I can click anywhere of the row and the will redirect to the detail page .
Notes : I do not want to use hyperlink column and do not want to fix the text for every row. I want to use datafield, CommandName and CommandArguement.
View 9 Replies
Aug 11, 2010
I have a detailsview bound in the code behind file. I want to format the column headers. How can I do that in the code behind file.
SqlCommand Cmd = new SqlCommand(SQLquery, connection);
SqlDataReader Dr = Cmd.ExecuteReader();
dvEstQty.DataSource = Dr;
dvEstQty.DataBind();
Cmd.Dispose();
connection.Close();
connection.Dispose();
View 4 Replies
Jan 30, 2010
I have a GridView bound to a DataTable that I construct. Most columns in the table contain the raw HTML for a hypelinklink, and I would like that HTML to render as a link in the browser, but the GridView is automatically encoding the HTML, so it renders as markup.
How can I avoid this without explicitly adding HyperLink, or any other, columns?
View 3 Replies
Aug 4, 2010
i want to create dynamically inside a datagrid templatecolumn some buttons and i wonder how can i refer to them from the vb code..
View 9 Replies
Oct 15, 2010
I have a gridview which makes use of a datasource. The columns are auto-generated.
Right now, my task is to make the first column into a url column. Does anybody know how to do it?
View 3 Replies
Mar 2, 2011
i am using asp.net 4.0
i want to remove Auto Genrated Columns of Gridview at Run Time and change the header text of these columns.
[Code]....
View 2 Replies