If you followed my previous post
var filteredUser = from U in collection
select new {U.fname,U.lname};
gridView.DataSource = filteredUser;
gridView.DataBind();
Now I am trying to do this:
Format the column names based on properties of U. So for example if U.fname chancges to U.FirstName then I want my gridview column name to reflect the same
If I enable paging through the design view, code compiles but when I launch the web app, it fails stating 'The data source does not support server-side data paging'
Edit::Found this for item # 2
link text
1) Are you using AutoGenerateColumns="True" on your GridView or binding them yourself? I would think that (1) would work if AutoGenerateColumns is true. You lose a lot of control over how the columns are displayed, but it ought to work. If you are binding them yourself, I think you will just need to update the bound column names whenever the name of the data field changes or alias the name in the select clause so that it remains the same.
var filteredUser = from U in collection
select new {FirstName = U.fname, LastName = U.lname};
2) Does your collection support IEnumerable<U> or just IEnumerable? I believe that LINQ uses Skip() and Take() to support paging so it would need to support the generic enumerable interface.
Related
I'm having some trouble with binding a DevExpress XtraReport subreport's datasource to it's containing report's datasource. The datasource is an object collection.
If I create a basic reports with sub detail sections all is well.
For example, the object collection is a list of companies. Each company has a list of addresses and a list of contacts. What I am attempting is to create a report with two subreports side-by-side for each (detail) company.
From several web articles, I thought this approach seemed like it would work:
report.ContactSubreport.ReportSource.DataSource = report.Datasource
which I call from a script using the subreport's BeforePrint event.
I also tried setting the datamember to the name of the sub collection:
report.ContactSubreport.ReportSource.DataMember = "Contacts"
Any help or suggestions would be greatly appreciated. Thanks!
From what I gather, you need to display only child collections' records that belong to the current master record.
In this case, it's better to handle the BeforePrint event of those XRSubreports and call there the XtraReport.GetCurrentRow method for a master report. This method call will return a master record (i.e., an instance of the "Company" object). This will allow you to pass the "Company.Addresses" list to the first subreport and the "Company.Contacts" list to the second one. Thus, the details that only correspond to each "Company" will be printed in both subreports.
I accomplish XtraSubReport dynamic or runtime data binding by doing Something like this and it WORKS perfectly
(VB.NET but can easily be implemented in C#)
NOTE:
The BandKind.Detail parameter below means the subreport was placed in the Detail Band. If not then specify the band of the main report where you placed the subreport in (eg. PageHeader, ReportHeader, PageFooter, etc)
The "XrSubreportInvoiceBank" is the name of the subReport that you created in the main report. You will need to change it to the name of the subreport in your main report
Dim MyDocument As New XtraReportInvoiceHardcopy
Dim BankSubreport As XRSubreport = CType(MyDocument.Bands(BandKind.Detail).FindControl("XrSubreportInvoiceBank", True), XRSubreport)
Dim BankAccount As DataTable = New DataTable 'You can put your Data in here
BankSubreport.ReportSource.DataSource = BankAccount
BankSubreport.Visible = True
Hello I'm developing a asp. Net page where I want to populate many tables in the ui
But I want it to be dynamic.
Eg: If I retrieve only 2 rows as per search criteria then I want to display only 2 tables.
I tried dynamic table creation using string builder but I got a null reference because the table Id was not being read . Is there any other way where I can create tables dynamically in the html page or should I do it in the code behind itself , then get the Id using flow control and then populate the table. Please help!!!
The problem of creatig tables dynamically has been rectified but now i cannot retrive their ids so that i can print values retrived from the datatbase in it using id.text command.
this is my code
StringBuilder htmlTable = new StringBuilder();
htmlTable.AppendLine("<table>");
htmlTable.AppendLine("<tr>");
htmlTable.AppendLine("<th>colum1</th>");
htmlTable.AppendLine("<th>colum2</th>");
htmlTable.AppendLine("<th>colum3</th>");
htmlTable.AppendLine("</tr>");
htmlTable.AppendLine("<tr>");
htmlTable.AppendLine("<td><asp:Label runat='server' id='lblt0'></asp:Label></td>");
htmlTable.AppendLine("<td>colum2data</td>");
htmlTable.AppendLine("<td>colum3data</td>");
htmlTable.AppendLine("</tr>");
htmlTable.AppendLine("</table>");
litTable.Text = htmlTable.ToString();
//litTable is the id of my asp:literal tag
You cannot create a table with a runat=server tag in this manner. Adding items to a literal control can only create client side markup not server side controls.
Your best route is to use a GridView as suggested or an HtmlTable
GridView: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx
HtmlTable: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable(v=vs.110).aspx
If your example really is as trivial as the one you provided an HtmlTable might be the easiest route. Though if you want to populate your table from a database or some other data source a GridView is your best option.
I have 2 combo boxes bound to a data-source, in order to make a search web page in ASP.NET. Both combo boxes are bound to database tables. The data-source determines its SQL SELECT statement based on the values of the combo boxes, so results are filtered. But, I want to include the case where the user doesn't want to set a value in some of the combos and wants to retrieve all database records regarding this combobox. I have included static entries in both combos (e.g. ), but how can I program the datasource, so as when is selected by user, no WHERE statement will be applied?
I found this answer a bit useful, but there are security issues and is not so straightforward.
Changing SqlDataSource.SelectCommand at runtime breaks pagination
Thanks in advance
Assuming that the value in the comboboxes when the user selects nothing is -1 you can modify your sql like this:
SELECT *
FROM TABLE
WHERE ((COLUMN_1 = #PARAM_1) OR #PARAM_1 = -1)
AND ((COLUMN_2 = #PARAM_2) OR #PARAM_2 = -1)
if you pass -1 as value for both parameters the query will return all the records in the table
Is there a way to iteratively reference an ASP.NET control based on it's name pattern? Perhaps by a "pointer" or something?
What I have are a large set of comboboxes (each with an associated DropDownList and TextBox control). The DropDownList always has an item selected by default, but the use may wish to submit a NULL value. I come up with the following code to handle three cases: NULL, Existing Item, New Item.
'TextBoxControl & DropDownListControl should iteratively reference their
' respective TextBox & DropDownList controls by the actual control name
If StrComp(TextBoxControl.Text, DropDownListControl.SelectedItem.ToString) = 0 Then
'When an Existing Item is selected, Do Something
ElseIf Not TextBoxControl.Text = "" Then
'When a New Item is entered, Validate & Do Something
Else
'When NULL, Do Something
End If
The problem is, with so many comboboxes, I could easily end up with hundreds of lines of code. I wish to handle this in a more dynamic way, but I do not know if it is possible to reference controls in this way. Say I wanted to reference all the TextBox Controls and DropDownList Controls, respectively.
I can do string formatting with a given naming pattern to generate a name ID for any of the controls because they are all named with the same pattern. For example by attaching a specific suffix, say "_tb" for TextBox Controls and "_ddl" for DropDownList Controls:
Left(item.SelectedItem.ToString, item.SelectedItem.ToString.Length - 3) + "_tb"
Can this sort of thing be done in VB? Ultimately, my goal is to take the value entered/selected by the user, if any, and send it to a stored procedure on SQL Server for insertion into the database.
Yes. Write your code inside of a function having parameters for the textbox and the dropdown, and then write the function in terms of those two parameters. Then you simply call that function for every set instead of copy/pasting code everywhere.
Don't attempt choosing things by name. That's fragile and imposes machine requirements on a field that'd designed for human consumption.
I am not sure if the samething that applies VBA will apply to your situation, but I had the same issue and was able to use:
Me.MultiPage1.Pages(1).Controls("ref" & i + 1).Value
where controls encompasses all controls on the userform ("Me"). So if the controls in your program conform to a consecutive naming structure it is easy handle if the above applies vb.net
When I attach a Site Map data source type to a site map control, I specify an ID for the data source.
Where in the code (or config files) is that ID associated with the corresponding Web.sitemap file?
Is it that there can be only one site map data source and the ID is actually redundant information?
Cheers.
DataSourceID is used when the source data is provided by another control of type DataSourceControl in the page, for instance a SqlDataSource control.
DataSource is used to provide the data directly. You should use either, but not both.
Look the DataSource is a control ,you can find it in the Data section of your tool box(ex:sqldatasource,objectdatasource,...etc).
You can set the datasource of your control(gridview for example)through one of two ways:
The first one is to drag the specific datasource control from the
toolbox and drop it in your page,then set the DataSourceID property
of your control by the id of the datasource control you has dragged.
The second one is through the code behind, you can set the
DataSource property of your control then call the DataBind().
You can't use both of the two ways at the same time. but you can solve this problem.if you wanna to use the both (each one under specific case or condition)then first you should set the other one by null before you can use the other one.
like this:
gv1.DataSource = null;
gv1.DataSourceID = ObjectDataSource1.ID;
gv1.DataBind();
and vice versa .