Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
Dear sir,
 
I am retrieving data fro database and that data stored in datatable.
 
and i want to bind datatable data to dynamic gridview columns in the specied cell.
 
I am trying like this.
 
we are developping the project 3-tier architeture
            dk = tbal.retriveheaderdata(clas, sec, k1, tim1);
 
            for (int hj = 0; hj < dk.Rows.Count; hj++)
            {
                TableCell tc = new TableCell();
                Label ll = new Label();
                ll.ID = f + hj.ToString();
                tc.Controls.Add(ll);
                tc.Text = dk.Rows[hj].ToString();
 
                
                GridView2.Rows[hj].Cells.Add(tc);
 

            }
Posted 24-Jan-13 14:15pm
Edited 24-Jan-13 14:26pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Sir ,
 
I don't want add rows with gridview.
I want to bind data to dynamic gridview cell.
Look at my gridview .
 
I want to bind data at "06:00:00-07:00:00" in specified cell But It added to outside of gridview.
 
Even i remove autogenerate columns from gridview as i am getting output as below.
 


Week 06:00:00-07:00:00 07:00:00-08:00:00 08:00:00-08:10:00 System.Data.DataRow
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

sir,
 
I used rowindex for merging gridview cells.I got output about my requirement, but my problem is i want to edit data in gridview cells.
 

I am using rowcommand i got value from 0th row. But remaining values get null values. So Please try to solve my problem.
this is my code check it once solve my problem
 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
 
            timetbal tbal = new timetbal();
            DataTable dk = new DataTable();
 
            dk = tbal.viewcount();
 
            int h = Convert.ToInt32(dk.Rows[0][1].ToString());
 
            if (e.Row.RowIndex == j)
            {
                e.Row.Cells[0].RowSpan = h;
                j = j + h;
            }
            else if (e.Row.RowIndex == j)
                e.Row.Cells[0].RowSpan = h;
            else
            {
                e.Row.Cells.Remove(e.Row.Cells[0]);
            }
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
        if (e.CommandName == "abc")
        {
            string s = e.CommandArgument.ToString();
            Session["murali"] = s.ToString();
            Response.Redirect("updatedata.aspx");
        }
    }
  Permalink  
v3
Comments
jibesh at 28-Jan-13 19:28pm
   
Please dont use the solution field to post your comments. use the 'Have a question or comment' widget to post your comments so that the author gets notification and he can reply to your query. If you post it as solution author may miss this and rare chance to look your query again.
 
Also if you want edit your question use 'Improve Question' link to modify your question
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Sir,
Please check out my code. Please checkout at " tc.Text = dt.Rows[hj].ToString();";
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public partial class Edittime : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt1 = new DataTable();
        timetbal obj = new timetbal();
        if (!IsPostBack)
        {
            dt1 = obj.class1();
            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                DataRow dr = dt1.Rows[i];
                DropDownList1.Items.Add(dr[0].ToString());
            }
        }
    }
 
    string clas;
    string sec;
    ArrayList jk = new ArrayList();
    string f = "murali";
    string tim1;
    DataTable dk = new DataTable();
    BoundField bField = new BoundField();
    BoundField bField1 = new BoundField();
    BoundField bField2 = new BoundField();
    BoundField bField3 = new BoundField();
    static TimeSpan t3;
    static TimeSpan t4;
    static TimeSpan n6;
    static TimeSpan n8;
    string k1;
    protected void Button1_Click(object sender, EventArgs e)
    {
        timetbal tbal = new timetbal();
        DataTable dt = new DataTable();
        string class1 = DropDownList1.SelectedItem.ToString();
        string[] k = class1.Split('-');
        clas = k[0].ToString();
        sec = k[1].ToString();
        dt = tbal.retrivevalues(clas, sec);
        string start_time = dt.Rows[0][0].ToString();
        string period_time = dt.Rows[0][1].ToString();
        string no_period = dt.Rows[0][2].ToString();
        string break_time = dt.Rows[0][3].ToString();
        string lunch_time = dt.Rows[0][4].ToString();
 

 
        //Header Text Values

        GridView2.Width = 1500;
        int n = Convert.ToInt32(no_period);
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                TimeSpan t1 = System.TimeSpan.Parse(start_time);
                TimeSpan t2 = System.TimeSpan.Parse(period_time);
                t3 = t1.Add(t2);
                string h = Convert.ToString(t1) + "-" + Convert.ToString(t3);
                GridView2.Visible = true;
                bField.HeaderText = h.ToString();
                GridView2.Columns.Add(bField);
 
            }
            else if (i < 2)
            {
                TimeSpan t1 = t3;
                TimeSpan t2 = System.TimeSpan.Parse(period_time);
                t3 = t1.Add(t2);
                Label6.Text = Convert.ToString(t1) + "-" + Convert.ToString(t3);
                GridView2.Visible = true;
                BoundField bField = new BoundField();
                bField.HeaderText = Label6.Text;
                GridView2.Columns.Add(bField);
            }
            else if (i == 2)
            {
                TimeSpan n1 = System.TimeSpan.Parse(break_time);
                t4 = t3.Add(n1);
                string k1 = Convert.ToString(t3) + "-" + Convert.ToString(t4);
                Label lbl = new Label();
                lbl.Text = k1.ToString();
                bField1.HeaderText = lbl.Text;
                GridView2.Columns.Add(bField1);
            }
            else if (i > 2 && i < 5)
            {
                TimeSpan t1 = t4;
                TimeSpan t2 = System.TimeSpan.Parse(period_time);
                t4 = t1.Add(t2);
                Label6.Text = Convert.ToString(t1) + "-" + Convert.ToString(t4);
                GridView2.Visible = true;
                BoundField bField = new BoundField();
                bField.HeaderText = Label6.Text;
                GridView2.Columns.Add(bField);
            }
 

            else if (i == 5)
            {
                TimeSpan n5 = System.TimeSpan.Parse(lunch_time);
                n6 = t4.Add(n5);
                string f = Convert.ToString(t4) + "-" + Convert.ToString(n6);
                Label lbl1 = new Label();
                lbl1.Text = f.ToString();
                bField2.HeaderText = lbl1.Text;
                GridView2.Columns.Add(bField2);
            }
            else if (i > 5 && i < 8)
            {
                TimeSpan t1 = n6;
                TimeSpan t2 = System.TimeSpan.Parse(period_time);
                n6 = t1.Add(t2);
                Label6.Text = Convert.ToString(t1) + "-" + Convert.ToString(n6);
                GridView2.Visible = true;
                BoundField bField = new BoundField();
                bField.HeaderText = Label6.Text;
                GridView2.Columns.Add(bField);
            }
 
            else if (i == 8)
            {
                TimeSpan n7 = System.TimeSpan.Parse(break_time);
                n8 = n6.Add(n7);
                string q = Convert.ToString(n6) + "-" + Convert.ToString(n8);
 
                bField3.HeaderText = q.ToString();
                GridView2.Columns.Add(bField3);
 
            }
            else
            {
                TimeSpan t11 = n8;
                TimeSpan t2 = System.TimeSpan.Parse(period_time);
                n8 = t11.Add(t2);
                string aa = Convert.ToString(t11) + "-" + Convert.ToString(n8);
                GridView2.Visible = true;
                BoundField bField = new BoundField();
                bField.HeaderText = aa.ToString();
                GridView2.Columns.Add(bField);
            }
        }
        GridView2.DataBind();
 
        for (int j = 1; j < GridView2.Columns.Count; j++)
        {
            tim1 = GridView2.Columns[j].HeaderText;
            dt = tbal.retriveheader(clas, sec, tim1);
           
            GridView2.DataSource = dt;
            GridView2.DataBind();
            k1 = dt.Rows[0][1].ToString();
          
            
            //dk = tbal.retriveheaderdata(clas, sec, k1, tim1);
            //for (int hj = 0; hj < dk.Rows.Count; hj++)
            //{
            //    DataRow dr = dk.Rows[hj];
            //    dk.Rows.Add(dr[0].ToString());
            //    //GridView2.DataSource = dk;
            //    // GridView2.DataBind();
            //}

 
            dk = tbal.retriveheaderdata(clas, sec, k1, tim1);
            for (int hj = 0; hj < dk.Rows.Count; hj++)
            {
                TableCell tc = new TableCell();
                Label ll = new Label();
                ll.ID = f + hj.ToString();
                tc.Controls.Add(ll);
                tc.Text = dt.Rows[hj].ToString();
 
                GridView2.Rows[hj].Cells.Add(tc);
 
            }
 

 
        }
    }
}
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100