Monday, February 18, 2013

how to change row data in column and display in gridview cell in asp.net


1. using sql query add CHAR(13) in various column and it will display like below text

    12 street town CLEVELAND pcode

2. Now  on GVLetter_RowDataBound event replace spcace with line break(<BR/>) as mention below

protected void GVLetter_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
        int id;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Cells[1].Text = e.Row.Cells[1].Text.Replace("\r", "<br />");
            e.Row.Cells[2].Text = e.Row.Cells[2].Text.Replace("\r", "<br />");

            id = Convert.ToInt32(e.Row.Cells[4].Text);
            if (id == 100)
            {
                ((ImageButton)e.Row.FindControl("ImagConfirm")).Visible = true;

            }
            else
            {
                ((ImageButton)e.Row.FindControl("ImagConfirm")).Visible = false;
            }
        }
    }

Result in griedview cell will as mention below


12
street
town
CLEVELAND
pcode

No comments:

Post a Comment