Monday, 1 December 2014

show multiple column in limited column in gridview


        i_temp = Convert.ToInt32(ds.Tables[0].Rows[0]["child"].ToString());// fetch all detail

// initailize column  which shows in gridview
   
        string ch1 = ds.Tables[0].Rows[0]["c_name1"].ToString();
        string ch1m = ds.Tables[0].Rows[0]["c_mobile1"].ToString();
        string ch1s = ds.Tables[0].Rows[0]["c_school1"].ToString();
        string ch2 = ds.Tables[0].Rows[0]["c_name2"].ToString();
        string ch2m = ds.Tables[0].Rows[0]["c_mobile2"].ToString();
        string ch2s = ds.Tables[0].Rows[0]["c_school2"].ToString();
        string ch3 = ds.Tables[0].Rows[0]["c_name3"].ToString();
        string ch3m = ds.Tables[0].Rows[0]["c_mobile3"].ToString();
        string ch3s = ds.Tables[0].Rows[0]["c_school3"].ToString();
        string ch4 = ds.Tables[0].Rows[0]["c_name4"].ToString();
        string ch4m = ds.Tables[0].Rows[0]["c_mobile4"].ToString();
        string ch4s = ds.Tables[0].Rows[0]["c_school4"].ToString();
        string ch5 = ds.Tables[0].Rows[0]["c_name5"].ToString();
        string ch5m = ds.Tables[0].Rows[0]["c_mobile5"].ToString();
        string ch5s = ds.Tables[0].Rows[0]["c_school5"].ToString();


//array to show values in a gridview
        string[,] details = { { ch1, ch1m, ch1s }, { ch2, ch2m, ch2s }, { ch3, ch3m, ch3s }, { ch4, ch4m, ch4s }, { ch5, ch5m, ch5s } };

        DataTable dt = new DataTable();
        dt.Columns.Add("StudentName");
        dt.Columns.Add("StudentMobile");
        dt.Columns.Add("StudentAddress");
        //dt.WriteXml();
        for (int i = 0; i < 5; i++)// insert array values in a gridview
        {
            dt.Rows.Add();
            for (int j = 0; j < 3; j++)
            {
                dt.Rows[i][j] = details[i, j].ToString();

            }
            dobj.tempchild(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), (i + 1).ToString());
        }
        GridView1.DataSource = dobj.tempchild1();
        GridView1.DataBind();
        dobj.tempchild2();//flush temp table

No comments:

Post a Comment