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


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

DATAGRID NULL ITEM REPLACE PROBLEM

Posted By: Deepak Sharma     Posted Date: September 21, 2008    Points:2   Category :ASP.Net
DATAGRID NULL ITEM REPLACE PROBLEM
I am normaly binding the dataset in grid. it has a coulumn 'Con1' in some cases it has value null, then there is another couluman 'consignee1' i want if 'con1' value is null then it pick the value of 'consignee1' .

like in label i have done.


txtto.Text = objrdr(
"ODAL").ToString
If txtto.Text = "" Then
txtto.Text = objrdr(
"dest").ToString
End If


How can i get this with grid.

<Columns>
<asp:BoundColumn DataField="con1" ReadOnly="FALSE" HeaderText="Consignee"></asp:BoundColumn>
</Columns>
i was trying this code for achiveing this.

dgdata.DataBind()
CSG1 = ds11.Tables(0).Compute("CONSIGNEE1", String.Empty).ToString
Label4.Text = CSG1


Protected Sub dgdata_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgdata.ItemDataBound

If e.Item.ItemType = ListItemType.Item And e.Item.Cells(10).Text = "0" Then
e.Item.Cells(10).Controls.AddAt(0, Label4)
e.Item.Cells(10) = Label4.Text

ds11.Tables(0).Compute("CONSIGNEE1)", String.Empty).ToString()
End If

End Sub


THANKS IN ADVANCE

Responses
Author: Amit Mehra             
Posted Date: September 21, 2008     Points: 5   

Hi,
There are two way you can do this one and the best way to handle in the SQL Query itself by using CASE statement.eg

CASE WHEN ISNULL(ColName,'')='' THEN -1 ELSE ColName END

Or in C# you can use

DBNull.Value.Equals(row[fieldName])

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Santosh             
Posted Date: October 08, 2009     Points: 5   

hi

u try with this

if objrdr("ODAL").toString = DBNull.value.ToString then
txtto.Text = objrdr("dest").ToString
end if


Regards
Santosh

Author: krishana singh             
Posted Date: October 16, 2010     Points: 5   

use ISDBNULL method with Eval



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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