Home  »  Forum  »  ASP.Net  »

How to pass sessin value in gridview rowdatabound?

 Posted By : chandru MPosted Date : 28/07/2011 01:53:03 PM Category : ASP.Net Points : 1

Dear all,

am using in gridview. this gridview using bind and display value., now one picture pass the session how?

am using for rowdatabound..
this coding am using:

if (e.Row.RowType == DataControlRowType.DataRow)
{
Image imgPhoto = (Image)e.Row.FindControl("imgPhoto");
Session["imgPhoto"] = imgPhoto.ToString();
}

Advance Thanks to all

Responses
 Author : Manoranjan Sahoo Member Level : BronzeDate : 28/07/2011 07:36:59 PM Points : 1

Hi,

can you tell me which type of control is imgPhoto?

and what you want to store in session?

i mean image or image url?



 Author : chandru M Member Level : BronzeDate : 29/07/2011 11:59:08 AM Points : 0

hi,

using image url



 Author : Manoranjan Sahoo Member Level : BronzeDate : 29/07/2011 04:19:11 PM Points : 4

Hi,

Please check below code. it will help you to solve your problem :

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("imgurl");
        dt.Rows.Add("http://manojaspxblog.files.wordpress.com/2011/07/potentialerror.jpg");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Session["url"] = DataBinder.Eval(e.Row.DataItem, "imgurl");
            string url = Session["url"].ToString();
        }
    }

Now below is the aspx code for gridview :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false" OnRowDataBound ="GridView1_RowDataBound" >
        <Columns >
             <asp:TemplateField HeaderText ="">
                 <ItemTemplate>
                    <img src='<%# Eval("imgurl") %>' alt=""/>
                 </ItemTemplate>
             </asp:TemplateField>
        </Columns>
        </asp:GridView>

Thank You.



Post Reply
Login to post Response.