Limey
Limey

Reputation: 2772

asp.hyperlink in gridview Format 0 as null

I am calling a giant stored proc via linq to sql that brings back some numbered data from 0 to 9. I would like to be able to display any zeros as nulls (so there is no hyperlink). I could do this in my stored procedure, but it would make it really hard to read and maintain (there is a lot of case logic going on).

I have the following code linking my procs results to the linqdatasource. Is there a way to update all records by formatting the data before binding or after the fact on the hyperlink?

protected void LinqMainMenu_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{

   var db = new App_Data.MYAppDataContext();
   e.Result = db.sp_MainMenuTest( (Int16)Session["myid"]);

}

Thanks

Upvotes: 2

Views: 209

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

You could reformat the results by doing something like:

e.Result = db.sp_MainMenuTest( (Int16)Session["myid"]).Select(i => new
{
    Field = (i.Field == 0) ? null : i.Field
});

If you can't use this approach, you cna always do it in GridView.RowDataBound event handler, get the cell value, if zero, reformat.

HTH.

Upvotes: 2

Related Questions