Click here to Skip to main content
15,897,371 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: ASP.NET 2.0 secure source code Pin
kaliem23-Oct-06 11:30
kaliem23-Oct-06 11:30 
GeneralRe: ASP.NET 2.0 secure source code Pin
Mircea Grelus23-Oct-06 12:23
Mircea Grelus23-Oct-06 12:23 
AnswerRe: ASP.NET 2.0 secure source code Pin
Guffa23-Oct-06 13:41
Guffa23-Oct-06 13:41 
GeneralRe: ASP.NET 2.0 secure source code Pin
kaliem23-Oct-06 14:10
kaliem23-Oct-06 14:10 
QuestionDatagrid add column Pin
eagertolearn23-Oct-06 6:46
eagertolearn23-Oct-06 6:46 
AnswerRe: Datagrid add column Pin
Mike Ellison23-Oct-06 8:51
Mike Ellison23-Oct-06 8:51 
GeneralRe: Datagrid add column Pin
eagertolearn23-Oct-06 12:17
eagertolearn23-Oct-06 12:17 
GeneralRe: Datagrid add column Pin
Mike Ellison23-Oct-06 12:49
Mike Ellison23-Oct-06 12:49 
Well, you have to know how to work with a TemplateColumn in a DataGrid. If you Google for something like "TemplateColumn DataGrid" you'll get lots of hits to articles that will help. Here's one:

http://aspnet.4guysfromrolla.com/articles/061002-1.aspx[^]

You'll notice in the article the use of the DataBinder.Eval() expression syntax. This syntax allows for data values to be evaluated and displayed in the template column. The article shows a good example of this.

Now in your case, you want a custom function that will determine whether a "yes" or a "no" should be outputted in the additional column. For the sake of example, let's say you have a field called "TotalSales" and you want to have a column labeled "Top Seller" show "yes" when the TotalSales value is greater than 1000. Otherwise, the column shows "no". So you might create a function in your script block that looks like this:
string DisplayTopSeller(int totalSales)
{
  if (totalSales > 1000)
    return "yes";
  else
    return "no";
}
Then, when defining your DataGrid, you would add a <TemplateColumn> in the <Columns> tag and use an expression that calls the DisplayTopSeller function, passing it the value of the TotalSales field:
<asp:datagrid id="myGrid" runat="server"
	          AutoGenerateColumns="False">	
  <Columns>
    . . . whatever columns come first . . .
    
    <asp:TemplateColumn HeaderText="Top Seller">
      <ItemTemplate>
        <%# DisplayTopSeller(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "TotalSales"))) %>
      </ItemTemplate>
    </asp:TemplateColumn>
    
  </Columns>	
</asp:datagrid>
If you are using .NET 2.0, you can substitute the shorthand Eval("TotalSales") syntax for the longer DataBinder.Eval(Container.DataItem,"TotalSales"). So in 2.0, your databinding expression could look like this:
<%# DisplayTopSeller(Convert.ToInt32(Eval("TotalSales"))) %>

I hope this is helpful.
QuestionMTOM WSE 3.0 problem Pin
sunsmile23-Oct-06 6:11
sunsmile23-Oct-06 6:11 
QuestionUse different databases Pin
shapper23-Oct-06 5:10
shapper23-Oct-06 5:10 
AnswerRe: Use different databases Pin
ednrgc23-Oct-06 6:28
ednrgc23-Oct-06 6:28 
QuestionHow to develop a user control? Pin
Old Gun23-Oct-06 1:32
Old Gun23-Oct-06 1:32 
AnswerRe: How to develop a user control? Pin
ednrgc23-Oct-06 4:21
ednrgc23-Oct-06 4:21 
GeneralRe: How to develop a user control? Pin
Old Gun24-Oct-06 3:30
Old Gun24-Oct-06 3:30 
GeneralRe: How to develop a user control? Pin
Old Gun26-Oct-06 3:22
Old Gun26-Oct-06 3:22 
GeneralRe: How to develop a user control? Pin
Old Gun26-Oct-06 3:23
Old Gun26-Oct-06 3:23 
QuestionDropDownList Databinding Question Pin
Dayekh23-Oct-06 1:24
Dayekh23-Oct-06 1:24 
AnswerRe: DropDownList Databinding Question Pin
Paddy Boyd23-Oct-06 3:30
Paddy Boyd23-Oct-06 3:30 
GeneralRe: DropDownList Databinding Question Pin
Dayekh23-Oct-06 3:57
Dayekh23-Oct-06 3:57 
GeneralRe: DropDownList Databinding Question Pin
Paddy Boyd23-Oct-06 4:14
Paddy Boyd23-Oct-06 4:14 
GeneralRe: DropDownList Databinding Question Pin
Dayekh23-Oct-06 5:01
Dayekh23-Oct-06 5:01 
GeneralRe: DropDownList Databinding Question Pin
Paddy Boyd23-Oct-06 5:02
Paddy Boyd23-Oct-06 5:02 
QuestionRegarding flash intro Pin
rajesh22523-Oct-06 1:10
rajesh22523-Oct-06 1:10 
AnswerRe: Regarding flash intro Pin
ednrgc23-Oct-06 2:44
ednrgc23-Oct-06 2:44 
AnswerRe: Regarding flash intro Pin
Britney S. Morales23-Oct-06 3:52
Britney S. Morales23-Oct-06 3:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.