Search code examples
c#gridviewpaginationevalbind

sort and page result of data bind with eval by gridview


hi every one my problem is data is retrieved from sql and is shown in the label but all in once i can't separate data rows in all data is shown in one line please help

<asp:GridView ID="grid_advertise_2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                GridLines="None" OnPageIndexChanging="GridView2_PageIndexChanging" PageSize="1"
                ShowHeader="False" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <tr>
                    <td id="advertise_2">
                        <asp:Label ID="lbl_advertise_2"
                                   runat="server"
                                   Font-Names="Tahoma"
                                   Font-Size="12pt"
                                   ForeColor="black"
                                   Text='<%# Bind("TitleEn") %>'/>
                    </td>
                 </tr>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

in server code

protected void Page_Load(object sender, EventArgs e)
{
    string Path = "Article.aspx";
    Session.Add("Path", Path.ToString());
    if (!IsPostBack)
    {
        this.BindGridadvertise1();
        this.BindGridadvertise2();
    }
}

private void BindGridadvertise1()
{
    myConnection c = new myConnection();
    SqlDataAdapter da = 
      new SqlDataAdapter("select * from TblArticleWishka where ID >= 0 ", c.Cnn);
    DataSet ds = new DataSet();
    da.Fill(ds);
    grid_advertise_1.DataSource = ds.Tables[0];
    grid_advertise_1.DataBind();
}

Solution

  • hi guys i did i did it by creating new sells and give them cssclass` int j = 0;

    protected void grid_advertise_1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (j<=1)
       {
            myConnection c = new myConnection();
            SqlDataAdapter da = new SqlDataAdapter("select * from TblArticleWishka where ID>=0 ", c.Cnn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            int i = 1;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
    
                i++;
                TableCell a = new TableCell();
                a.CssClass = "advertise_1_" + i + "";
                a.Text = (string)dr["TitleEn"];
                e.Row.Cells.Add(a);
                a.DataBind();
            }
            j++;
       }
    }`