Pages

Monday, February 02, 2009

How to set the value of a control in ASP.net details view


 

Here in the picture I have a details view. I want to set a value for the SOP_CODE label from a cookie. I have done this using DetailsView1.FindControl function. But the question is when to call the function. There are several events for details view. The right one is this

 

protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e);

 

In this event you can do a lot of things with your details view

 

What I have done is

 

 

protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)

    {

        ((Label)DetailsView1.FindControl("label_sopCode")).Text = Request.Cookies["SOP_CODE"].ToString();

    }

 

 

And it worked fine.

Enjoy..

No comments:

Post a Comment