Monday, March 12, 2012

how to handle null values for Templatefield, hyperlink etc...

Nulldisplaytext work for asp:boundfields
<asp:BoundFieldDataField="fax"HeaderText="fax"SortExpression="fax"/>

how to make it work for

<asp:HyperLinkFieldDataNavigateUrlFields="supplierID"DataNavigateUrlFormatString="editSupplier.aspx?supplierID={0}"DataTextField="supplierID"HeaderText="SupplierID">
<ItemStyleHorizontalAlign="Left"/>
</asp:HyperLinkField>

<asp:TemplateFieldHeaderText="Supplier Name"SortExpression="SupplierName">
<ItemStyleHorizontalAlign="Left"/>
<ItemTemplate>
<%#Eval("SupplierName")%>
</ItemTemplate>
</asp:TemplateField>

In a TemplateField, you can use a databinding statement like this (in C#):

<asp:TemplateField>
<ItemTemplate>
<asp:Label runat=server Text='<%# Eval("CustomerID") == null ? "nullDisplayText" : Eval("CustomerID") %>' />
</ItemTemplate>
</asp:TemplateField>

There's no easy way to do this with a HyperLinkField, so consider converting your HyperLinkField to a TemplateField to do the method above.


This is what I use to do to handle null,

select isnull(field,'')as field from table. If i do this do you think it will be an performance issue as I have to do for each an every field.

and what's the replacement for your code in VB

Text='<%# Eval("CustomerID") == null ? "nullDisplayText" : Eval("CustomerID") %>'


bhavin78 wrote:

and what's the replacement for your code in VB

Text='<%# Eval("CustomerID") == null ? "nullDisplayText" : Eval("CustomerID") %>'

Try,

Text='<%# IIF(Eval("CustomerID") is nothing,"nullDisplayText",Eval("CustomerID")) %>'


which one would be better to use as far as performance goes

isnull("data",'') in sql query

or

Text='<%# IIF(Eval("CustomerID") is nothing,"nullDisplayText",Eval("CustomerID")) %>'

Labels: , , , , , , , , , , , ,

How to handle buton event inside datagrid

Hi All

In Datagrid with the help of template i am able to place a button like this

<asp:TemplateColumn HeaderText="Patient_id">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Patient_id") %>'>
</asp:Label>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="redir" ></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Patient_id") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

i added redir in aspx page like this

protected sub redir( sender as object, e as eventargs)

//code

end sub

when i m invoking that with Onclick its generating the error

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@dotnet.itags.org. Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Help Needed

Thank u

Baba

You cant use event handlers directly like that when handling events of a nested control. The nested control bubbles up its event and you can handle them as shown in this article:

http://blogs.msdn.com/paraga/archive/2005/11/26/497120.aspx

Hope this helps,

Vivek

Labels: , , , , , , , , , , ,