databind to a cookie

J

Jack

How can you databind a textbox control to a cookie value? I actually
have 10 textboxes that need to be programmatically filled with text
strings from a cookie and databinding to the cookie is where this has
led me. How can I populate a datagrid with the cookie values?

thanks,

Jack
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Jack,


To Bind to a DataGrid you could parse the cookie and save the values on a
Array or ArrayList then you can bind that array List to the grid.

To Bind it to the textboxes you can use something like this:
( in aspx file )
<asp:TextBox id="id1" Text='<%# GetCookieValue( PARAMETER) %>'
runat=server>

PARAMETER will be a value indicating what part of the cookie you will want.
for this example let's assume that the cookie is a comma separate set of
strings. then PARAMETER can be an integer

( in the cs file )
protected string GetCookieValue( int index )
{
string[] parts = Request.Cookies[COOKIE_NAME"].Value.Split( new char[]
{','} );
return parts[index];
}


Hope this help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top