.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
satyapriyanayak
SP
Ashutosh Jha
ASPEvil
Post New Web Links

WebGrid: column definition - Set 'style:' parameters depending on value

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net
 

Hi.
I have a list of objects (List<myObject>) which I pass to a webGrid. I would like to set cells for a column of the table to a specific value depending the object's 'StatusColor' property. Something like

List<myObject> myObjectList = 
WebGrid webGrid = new WebGrid(source: myObjectList, ..);
@webGrid.GetHtml(
columns: webGrid.Columns
(
webGrid.Column("Status", "Status", format: @<text>@item.StatusName</text>, style:

@<text>@item.StatusColor</text>

)
)
)

But for some reason, I get "cannot convert from 'lambda expression' to 'string'". When I remove the @<text> suround the item property, I get "the name '@item' does not exists in the current context"

For the 'format:' part, it works fine.
Thanks




View Complete Post


More Related Resource Links

How to change image\parameters on style definition ?

  

I define some new button style.
The style default background is image X.bmp and when on 'mouseOver' is true the image is changing to Y.bmp

I have 10 buttons on the code that need to use this style - and each of the button need to show different image as default different image on 'mouseOver' event.

I can set the bitmap on each button on the button constructor - but i don't know how to set the image in this case on the style definition level.

Someone can help here ?


DataGrid: Tailor Your DataGrid Apps Using Table Style and Custom Column Style Objects

  

One of the most enduring challenges in writing user interfaces is figuring out how to display large amounts of data efficiently and intuitively without bewildering the user. The problem becomes particularly thorny when the interface must reflect hierarchical relationships within the data that the user needs to modify. The Windows Forms DataGrid control gives developers a powerful and flexible tool to meet this challenge. This article explains its basic operations and shows how to extend the DataGrid to display columns of data in an application-appropriate manner.

Kristy Saunders

MSDN Magazine August 2003


Filter items with a date column with parameters start date and end date on a sharepoint list?

  
If I have alist with a view that has the columns Title, Status and Status Date and the view has some items. How Can I add a filter with two parameters, start date and end date, to only show records with status date equal to or greater than parameter start date and status date is less than or equal to parameter end date? This is a sharepoint online site and I can't create and deploy custom code, can use SPD though. Do I need to use SPD or is this something I can do in the list settings? Thanks in advance.   Edit: I had a look here http://www.endusersharepoint.com/2009/09/29/sharepoint-date-filter-filtering-a-list-by-greater-than-or-equal-to-date/ but I don't have the Date Filter web part.

How to pass page column value to data view parameters

  
Hi All, I have a page library with custom column, lets call it "FormCourseId". On that page I have data view which retrieves data from custom list filtered by page column "FormCourseId". In parameter wizard creates the following tag <ParameterBinding Name="ListCourseId" Location="Form(FormCourseId)" DefaultValue=""/> Then I try to use that parameter in XSLT of data view as a filter creteria.  <xsl:param name="CourseId"></xsl:param> It does not work for me. If I change data view parameter source from Form to Query String and pass parameter as url one it works fine. What is wrong with page column parameter binding? May be if FormCourseId column is not presented in form layout as a field(I do not need to show that field in user form of the page) it could not be treated as form parameter?

Wierd case of: Msg 213, Column name or number of supplied values does not match table definition

  
Hi, I'm working on several triggers (that happen after insert or update) in order to log the changes in a different table. They all follow a similar syntax and are working fine, except for this one... I've reduced the next code to the minimum that gives an error, so we can safely assume the other parts of the trigger are working fine. INSERT INTO [Adt].[WardUnitStayLog] SELECT t.* FROM [Adt].[WardUnitStay] t INNER JOIN inserted i ON i.[Id] = t.[Id]; I've used this same syntax (but on different tables) in other triggers, and these are working perfectly fine. The above query provides the next error: Column name or number of supplied values does not match table definition. I've checked both tables for differences in the columns, but to no avail... (I've checked them manually and by outerjoining the information_schema.columns) (I've also checked the order in wich these columns are defined, they match over the two tables) These are the creation scripts for the tables: CREATE TABLE [Adt].[WardUnitStay] ( [Id] [dbo].[Id] IDENTITY(1,1) NOT NULL, [UnifiedUnitStayId] [dbo].[Id] NOT NULL, [WardCd] [dbo].[Cd] NOT NULL, [_FirstAtTm] [dbo].[Dtm] NOT NULL, [_IsReservation] BIT NOT NULL, [_LastAtTm] [dbo].[Dtm] NOT NULL, [_LastBedCd] [dbo].[Cd] NULL, [_LastPhysicianUid]

Schema comparer mistake in table-valued function (Nullability in column definition)

  
Hello. In my database i have table valued function. In its definition nullability of column is not set directly. This column has a user-defined data type. So the question is: is this column nullable? As i can see here: http://msdn.microsoft.com/en-us/library/ms174979.aspx   When column nullability is not explicitly specified, column nullability follows the rules shown in the following table. Column data type Rule Alias data type The Database Engine uses the nullability that is specified when the data type was created. To determine the default nullability of the data type, use sp_help. It should be not null, as user defined type is declared as not null. SMO says, that column is not null, but schema compare says it is nullable. Who is wrong and why?

Style depending on Windows Theme

  
Hi,   I want to style a ToolBar differently depending on which theme is used (Aero or Classic) in Windows 7. I have found some examples on the net but all describe how to do this on custom controls. I want to do this on a normal control. Is that possible?

Trying to apply style to a gridview column programatically..

  

I have a grid view that is bound from my code behind.   If the text of a label is equal to the value of a querystring, I want to apply a specific class/style that is in my .css.  I've tried this, but doesn't seem to have any affect...  How can I set the class for a column in the gridview if the two values match?   

 protected void gvMenu_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblSubSectionIDForComparing = e.Row.FindControl("lblSubSectionID") as Label;
            Label lblSubSectionNameForComparing = e.Row.FindControl("lblSubSectionName") as Label;

            if (lblSubSectionIDForComparing != null)
            {
                if (lblSubSectionIDForComparing.Text == Request.QueryString["SubSectionID"])
                {
                    e.Row.Cells[2].CssClass = "SubSectionNav";  <-- This is what I thought would work...
                  }
             }
        }
    }


 


disable foreign key link depending on column value in the current row using Attributes

  

Hi ,

I want to disable  some foreign key links depending on column value in the current row

I am trying to have attribute like this :


[Disablelink("True","OrderDate","==","null"] 

 public partial class Order
    {

        internal sealed class OrderMetadata
        {
          
            [Disablelink("True","OrderDate","==","null"]
            public EntityCollection<Order_Detail> Order_Details { get; set; }

            public Nullable<DateTime> OrderDate { get; set; }

          

         }
        }
    }


I had a look at Mr. Steve code for row highlighting , Conditional UIHint

http://csharpbits.notaclue.net/2010/07/conditional-row-highlighting-in-

SQLCommand parameters for column name

  

Hello!

I want to insert column names as parameters into a SELECT statement (for MSSQL 2008): 


string sql = "SELECT @clm1 FROM db.tblUser WHERE aspUserId = @userId";
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlParameter parUser = comm.Parameters.Add("@userId", SqlDbType.NVarChar);
            SqlParameter parColumn= comm.Parameters.Add("@clm1", SqlDbType.NVarChar);
            parUser.Value = aspUserId;
            parColumn.Value = "clm1";
            conn.Open();
            string str = comm.ExecuteScalar().ToString();


and the ExecuteScalar returns the column name ("clm1") instead of the value.

But if I change the SELECT to "SELECT clm1 FROM db.tblUser WHERE aspUserId = @userId", ExecuteScalar returns the value of the "clm1" column (which is want I want!).

In what way can I insert column names into SQL statements as parameters? The purpose is to build dynamic SELECT commands...

thx,

M



ComboBox with Parameters & Column visibility

  

Dear All,

I have a report with many fields displaying in the report. I am checking the visibility of the columns.

When i am defining a separate parameter of boolean type iam able to hide the column visibility using the following xpression,

=IIf(Parameters!Col1.Value="True",False,True)

 

Now i have defined a parameter of

Data type = text, allows multiple values

Available values - in 'Specify Value' have specified the resulting column names in the Label and Value fields.

No Default Value.

So the parameter field holds all column names in a combobox with check box aside.

i am trying to hide the columns with the expression in the column visibility properties. but i am not able to use the same xpression, for it is only taking the parameter name in xpression but not the defined combobox values.

 

kindly help me with the formula..

I need to display the columns that are alone checked in the parameter combobox value.

 

Thanks !!


Column Alias Usage Everywhere in a Query Following Definition

  

In the following query, you cannot use the column aliases in WHERE and GROUP BY clauses, then suddenly like thunder from the blue, you can use it in the ORDER BY clause. It is counter-intuitive. It is counter-productive as well.

SELECT	[Year]=YEAR(OrderDate),
		[Month]=MONTH(OrderDate), 
		TotalSales=SUM(TotalDue)
FROM AdventureWorks2008.Sales.SalesOrderHeader
WHERE YEAR(OrderDate) > 2002
GROUP BY YEAR(OrderDate), MONTH(OrderDate)
ORDER BY [Year],[Month]
/* Year	Month	TotalSales
2003	1	1968647.184
2003	2	3226056.1486
2003	3	2297692.9898
*/	

I made a suggestion to enable column alias usage everywhere in a query. You can vote for this feature at Connect:

https://connect.micro

Gridview column changing visibility depending on a row.text

  
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {           
 if (e.Row.Cells[1].Text == null)
            {
                GridView1.Columns[1].Visible = false;
            }

        }


and im not getting the result i expected =\

 


How can I pass parameters to my Business Data Column?

  
I have a custom list in which I have created a  Business Data Column that pulls data from a web service.  I have written the ADF file, it is installed on the server and I can get to the service's fields via the Business Data Type picker. However, and this is the part I can't figure out how to do: the web service requires 2 parameters be passed to it.  These parameters exist in other fields of the list item.  How do I make that association and pass those parameters?  Is this possible?

Also, I have not delved into using Visual Studio yet for SharePoint development, so I only have the UI and Designer as my tools.  I am on MOSS 2007.

Edit - I found this article: http://sharepointmagazine.net/technical/administration/everything-you-need-to-know-about-bdc-part-4-of-8.  Toward the bottom it explains how to do a 1:1 mapping of the list item to, in his example, the database item.  This is similar to what I need to do, except mine is a web service and it requires two parameters to identify it.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend