Click here to Skip to main content
15,890,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey everyone

I have a label lblUID on which i am populating id of db table which has data type unique identifier.How can i convert lblUID.Text from Guid to string and again string to Guid.And how to check whether its empty or not like IsNullOrEmpty in string?i have to use this method--

if (RadGrid1.SelectedItems.Count != 0)
            {
                txtItemNamePanel.Focus();
                pnlExternalForm.Visible = true;
                RadGrid Grid = (this.FindControl("RadGrid1") as RadGrid);
                string Pid = Convert.ToString(Grid.SelectedValues["Pid"]);
                string query = "SELECT * FROM tblProducts where Pid=" + Pid;
                GetProductInfoForEdit(query, Pid);
                BindGrid();
            }


except for i have UID in place of pid that is unique identifier.
lblIdPanel.Text = ProductId; should be equal to UID.

Thanks
Amit
Posted
Updated 3-Nov-10 18:58pm
v2

i mean:

<pre>string str = "cd7fc78e-de3c-4761-9192-4cfb7a6088e5";
            Guid g = new Guid(str);


 
Share this answer
 
Check to see if the Guid object is null.

Guid guid = Guid.NewGuid();
if (quid == null)
{
  // do something
}


To convert it to a string (passing paramneters to the ToString() method causes the returned value to formatted in specific ways see here: http://msdn.microsoft.com/en-us/library/97af8hh4.aspx[^]):

string myGuid = guid.ToString();


To convert a string to a guid:

Guid guid = new Guid(myguidstring);


If you had googled it, you would have found this:

http://msdn.microsoft.com/en-us/library/system.guid.aspx[^]

All it takes is a little initiative and common sense to save yourself buttloads of time waiting for someone to answer your question.
 
Share this answer
 
v2
lblIdPanel.Text = ProductId.ToString();
 
Share this answer
 
to convert string to Guid :
<pre>string str = "";
           Guid g = new Guid(str);


 
Share this answer
 
Comments
CPallini 4-Nov-10 9:39am    
You are surely joking, Mr.Souidi, aren't you?
souidi abderrahman 4-Nov-10 9:47am    
yes, :)

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