Click here to Skip to main content
15,885,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to pass null value to label in asp.net??
C#
label.Text =null;
label.Text="";
label.Text=DBNULL;

not working?????
Posted
Updated 11-Oct-12 0:38am
v2
Comments
Toniyo Jackson 11-Oct-12 6:20am    
Are you telling that label.Text="" also not working?

C#
label.Text = string.Empty;


If you want a label to display 'empty', just assign string.Empty.
 
Share this answer
 
Comments
Hasiya 11-Oct-12 6:17am    
label.Text = string.Empty; not working
Dylan Morley 11-Oct-12 6:20am    
Trust me, it works. What do you even mean 'not working'? Does it error - do you get an exception? Post what code you have, and what you mean by it's not working
Hasiya 11-Oct-12 6:23am    
No...i want to pass null value to datatable.
this is my list
List<webcontrol> controllList = new List<webcontrol>();
controllList.Add(lblgettime);


i wnat to pass lblgettime to null value..
Toniyo Jackson 11-Oct-12 6:32am    
Use System.DBNull.Value to pass Null value to database.
You need to pass DbNull.Value for DataTime field in this case.
Please refer How to pass the null value to datetime datatype in asp.net?[^] for the same type of issue.

Thanks...
 
Share this answer
 
if you set null label text will always be blank ("") and not null. hence, you can use the following:-

C#
protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = string.Empty ; // OR  Label1.Text = null ; 
    Label2.Text = (String.IsNullOrEmpty(Label1.Text) ? "null" : "not null");
}
 
Share this answer
 
v2
Comments
Hasiya 11-Oct-12 6:34am    
not working
Hasiya 11-Oct-12 6:39am    
List<sqlparameter> parameters = new List<sqlparameter>();
parameters.Add(new SqlParameter("@couriercode", SqlDbType.VarChar, 50));
parameters.Add(new SqlParameter("@Phonenum", SqlDbType.Int));
parameters.Add(new SqlParameter("@receivedTime", SqlDbType.DateTime));
parameters.Add(new SqlParameter("@gettime", SqlDbType.DateTime));
parameters.Add(new SqlParameter("@Remarks", SqlDbType.VarChar, 200));
parameters.Add(new SqlParameter("@Status", SqlDbType.Int));

List<webcontrol> controllList = new List<webcontrol>();
controllList.Add(dropdowncourier);
controllList.Add(dropdowngetphone);
controllList.Add(lbltime);
controllList.Add(lblgettime);
controllList.Add(txtremarks);
Hasiya 11-Oct-12 6:40am    
I want to pass null value to lblgettime,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900