I was using Gridview for a while now and I have noticed that its very easy to create a simple table and populate it with date f.e.
ID Name Surename Phone .....
1 Tom Tomtom 111122233
2 Vic VicVic 21231231
3 Rik RikRik 123545343
So here we have a simple gridview with three records, every record is in one line!
What I need is to put one record info in three lines like here:
ID Name Surename Phone .....
/ 1 Tom Tomtom 111122233
record1 { Additional info: blablabla
\ More info: xxxxx
/ 2 Vic VicVic 21231231
record2 { Additional info: blablabla
\ More info: xxxxx
/ 3 Rik RikRik 123545343
record3 { Additional info: blablabla
\ More info: xxxxx
So here we have a Gridview and here we show One record's info in three lines...So how to do this?
I was using this code to populate my gridview when I have an Object of data but this works only with a single lines of records
private void grdMyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
MyObject ObjectEl = (MyObject)e.Row.DataItem;
e.Row.Cells[0].Text = ObjectEl.ID.ToString();
e.Row.Cells[1].Text = ObjectEl.Name.ToString();
e.Row.Cells[2].Text = ObjectEl.Surename.ToString();
LinkButton lbtConfigure = (LinkButton)e.Row.Cells[3].FindControl("lbtConfigure");
lbtConfigure.CommandArgument = Convert.ToString(ObjectEl.ID);
}
}
Templating rows like this is possible in a gridview, but the listview control is much better suited to this type of data.
Take a look here, this will get you started.
http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx
you can use templating for this purpose.
insert tables inside header template and item template(according to your need).
inside tables you can insert labels.
bind labels with the columns in your datatable.(Eval("columnname")).
now you got the gridview as you expected.
Related
I have a column in my stored procedure which contains following data, in row by row manner :
Ajay Tegar (1052), Amol Kumar Gupta (1409), Dilip Yadav (1369)
Now I want only data in brackets to be bold and else everything regular, like so:
Ajay Tegar (1052), Amol Kumar Gupta (1409), Dilip Yadav
(1369)
I am using grid view to show these data in asp.net web page.
I used below code at code side to bold particular text in gridview -
Label lbl_emp_name = (Label)e.Row.FindControl("lbl_empName_report");
if (lbl_emp_name.Text.Contains("("))
{
string [] splitedText = lbl_emp_name.Text.Split('(');
lbl_emp_name.Text = splitedText[0] + "<b>(" + splitedText[1] + "</b>";
}
I have set up a grid panel with groupingsummary (tried grouping feature also - no luck) feature and actioncolumn [for deleting and editing records]. I'm wrestling a couple of days to get row index but to no avail.
Without the groupingsummary feature the actioncolumn works as it should, i can edit or delete a row by clinking the action icons using the following code to select a row:
handler: function(grid, rowIndex) {
rec = grid.getStore().getAt(rowIndex);
rowId = rec.get('rowId');
rowName = rec.get('rowName');
...
...
}
Then i execute an Ajax request to the server for the corresponding action [edit, delete].
How do i select a row in a grid with groupingsummary feature? Is it a bug?
Anyone have sample lookup code for AOT objects? (or know where to find the one they use for the AX properties window)
I need to replicate the functionality that you see in several fields in the properties window. The ExtendedDataType field is a good example. Type a few letters, hit the down arrow, and a filtered list of AOT ExtendedDataType objects appears.
I've been trying to use treeNode findChildren to build my custom lookup list, but it is very slow. Whatever method AX is using happens instantly.
Thanks
Try this:
Dictionary d = new Dictionary();
int i;
int cnt = d.tableCnt();
TableId tableId;
str nameForLookup;
for (i = 1; i <= cnt; i++)
{
tableId = d.tablecnt2id(i);
nameForLookup = tableid2name(tableId);
}
Queries to the Model/Util*Element tables will not be cached, and are relatively slow due to the number of records that they contain.
There may be other factors slowing down execution as well. If you are on 2012, for lookups, you may want to build a temp table with an XDS() method, which populates itself using the above code, then you can simply select from that table (and it will be cached for the session):
create a SQL Temp table (e.g. with a name like MyTableLookup), add a name column
add a method like this:
public RefreshFrequency XDS()
{
MyTableLookup tableLookup;
ttsbegin;
// Use the above code to insert records into tableLookup
ttscommit;
return RefreshFrequency::PerSession;
}
bind your form to MyLookupTable
You may develop an estándar EDT linked to the UtilElement Table properly filtered. This will show a list of objects and will have same functionality of all table-linked text fields.
I don't know if the follow code snippet intend to work in this way, because sometimes we "as developers" try automate creation of data display control where number of fields are uncontrolled and with similar data-binding, so before I review the application some guys left this :
Under ActiveReport_ReportStart() event :
for (Ind = 1; Ind <=CM.Length; Ind++) {
if (Ind == 1) {
Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH8"]).Left + 0.05f;
} else if (Ind == 2) {
Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH9"]).Left + 0.05f;
} else if (Ind == 3) {
Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH10"]).Left + 0.05f;
}
TextBox TB = new TextBox();
TB.Size = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Size;
TB.Font = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Font;
TB.Width = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Width;
TB.Height = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Height;
TB.VerticalAlignment = VerticalTextAlignment.Top;
TB.Location = new System.Drawing.PointF(Left, ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Top);
TB.DataField = "ColorText" + Ind + ColorwayNumber;
rpt.Sections["Detail"].Controls.Add(TB);
It doesn't have compilation error when is previewed, also others fields that are not auto-generated are displayed correctly (ReporHeader, ReportFooter), but IMHO I think is better to replace this mechanism by a subreport inside the detail section, of course these fields have to be displayed in Detail section of the report. Anyways I would like to see some recommendations because if is possible to auto-generated textbox or labels in runtime I will have to explain to boss why this code was not working, and if I have to use subreports instead, I need to know how to pass parameter (at least I need to work with two parameters for generate another sql query for it) and what "event" is proper to put script into it..
After I discovered that most important problem is to get report format changes by how many field/textbox were added to report detail in runtime restricted by a sqlquery return value, for example :
Returned SQLQuery value = 4
10 fields generated for detailed row 1
6 fields for row 2
4 fields for row 3
Detail fields are bound to a SQL Store Procedure*
Report will supossed to be printed/showed in this way :
//Report Init
Page 1 :
|field 1|field 2|field 3|field 4|
------------------------------------------------------
row1 | valA1 | valA2 | valA3 | valA4 |
------------------------------------------------------
row2 | valB1 | valB2 | valB3 | valB4 |
------------------------------------------------------
row3 | valC1 | valC2 | valC3 | valC4 |
------------------------------------------------------
Page 2 :
|field 1|field 2|field 3|field 4|
------------------------------------------------------
row1 | valA5 | valA6 | valA7 | valA8 |
------------------------------------------------------
row2 | valB5 | valB6 |
------------------------------------------------------
row3
------------------------------------------------------
Page 3 :
|field 1|field 2|field 3|field 4|
------------------------------------------------------
row1 | valA9 | valA10|
------------------------------------------------------
row2
------------------------------------------------------
row3
------------------------------------------------------
//End of Report
Any help will be appreciated
Thank you so much
It is perfectly fine to dynamically create fields on a report at runtime. The creation of those fields do indeed need to be done in the reportstart event or earlier (i.e. before calling ActiveReport.Run).
However, you could place the same logic to dynamically create those fields in a subreport and pass a parameter too, but in general subreports do impose additional overhead (and an additional query in most cases) so I wouldn't use a subreport unless there is a compelling benefit. However, there is a walkthrough on passing parameters to a subreport here.
The only thing that looks suspect in your code is the following line:
TB.Location = new System.Drawing.PointF(Left, ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Top);
You are using the Top value from a control in the PageHeader, but TB is in the Detail section. I can understand reusing the Left value, but reusing the Top value wouldn't be consistent across different sections (Top is it's vertical position from the top of the section containing the control)
Now, it sounds like sometimes these fields do not appear on the report. Some things you can verify to troubleshoot the problem:
Determine if there is a binding problem or a visual/location problem. TO do this, just give the textbox a border or a background color or something so you can see it even if there is no text (due to failed data binding).
Start logging out the position of each textbox and the datafield value to a log file. When you notice the problem, go back to the log and see if you can identify what triggers the problem (maybe a specific index, location or datafield value?).
Finally, make sure that the page size (determined by the system's default printer) is not changing and maybe cutting off one of your dynamically added textboxes.
I need to add a secondary (header) row to my ASP.NET GridView (which is already customized so I can access any part of the event lifecycle).
It's additional data that I want aligned with some of the columns.
It should look like this
Period | May | June | July | Aug -- Header
Basevalue | 3000 | 1500 | 1200 | 4000 -- EXTERNAL DATA
---------------------------------------
Item 1 | 100 | 200 | 300 | 400
Item 2 | 100 | 200 | 300 | 400
I managed to add a row with below code, but I am unable to create any kind of custom event where I could gain access and write my custom data into that cell. I tried the following, but during any event I could find (like OnRowCreated or PrepareControlHierarchy), it's either too late (after databinding) or the inner table is not initalized.
int rowIndex = 0;
GridViewRow secondHeaderRow = new GridViewRow(rowIndex, -1, DataControlRowType.Header, DataControlRowState.Normal);
secondHeaderRow.TableSection = TableRowSection.TableHeader;
foreach (DataControlField col in this.Columns)
{
TableHeaderCell cell = new TableHeaderCell();
cell.DataBinding += new EventHandler(OnHeaderCellDatabinding);
secondHeaderRow.Cells.Add(cell);
}
InnerTable.Rows.AddAt(rowIndex, secondHeaderRow);
How can I hook up to the GridView lifecycle to write in the header row?
hey niles,
we can use the caption to some HTML tags and start building the extra headers
please refer this link for your problem
CLICK HERE
hope it will help you
Try this. Merging columns in GridView/DataGrid header