Click here to Skip to main content
15,915,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create grid view like this
first row should be current months dates like aug 1 to 31


-----------------------------------------------
staff id| 1 | 2 | 3 | 4 |......| 29 | 30 | 31 |
------------------------------------------------
1 | p | p | a | a |......| p | a | a |
------------------------------------------------
Posted
Updated 24-Aug-14 20:00pm
v2
Comments
What is the issue?
ganew 27-Aug-14 1:56am    
i want auto generat0 col like col name 1,2,3,...,31 like month days
&
how to add image in my question here...then i can told what i want
Prasad Avunoori 25-Aug-14 6:27am    
What do you want?

Try this
You can Create Grid view in aspx in advanced or Create gridview in .cs page (Code not provided for same)

C#
DataTable dt = new DataTable();

for(i=0;i<32;i++) //To print date , Considering 31 days for month 
{
   dt.Columns.Add(i.ToString());
}
for(j=0;j<10;j++) // Considering 10 entries - For Rows 
{
   DataRow drow = dt.NewRow();
   for(k=0;k<32;k++)
   {
      //Your Logic
      if( k % 2 == 0)
         drow[k] = "P";
      else
         drow[k] = "A";

   }
   dt.Rows.Add(drow);
}

grdView.DataSource = dt;
grdView.DataBind();
 
Share this answer
 
Comments
ganew 27-Aug-14 5:32am    
thank you ChintanShukla

if you want to see this question properly
Question : how to add and catch event of linkbutton inside the gridview by dynamically
submitted in codeproject

i am getting the col of gridview link month and i add link button in that col which col having data, when i am clicking on that linkbutton the link button cant fire any event


code:

if (e.Row.RowType != DataControlRowType.Header)
{

DataSet ds = new DataSet();
planningStaffCommon.StaffID = sid;
ds = objDALPlanningModule.GetStaffMeetingData(planningStaffCommon);
if (ds.Tables[0].Rows.Count > 0)
{
for (int J = 0; J < ds.Tables[0].Rows.Count; J++)
{
//getting data from data set
dateofcell = Convert.ToString(ds.Tables[0].Rows[J]["FromDate"]);
from = Convert.ToInt16(ds.Tables[0].Rows[J]["datea"]);
string clientids = Convert.ToString(ds.Tables[0].Rows[J]["MeetingType"]);
colorvalue = Convert.ToInt32(ds.Tables[0].Rows[J]["ColorValues"]);
//set Color
if (colorvalue == 1)
{
//DataSet dscolor = new DataSet();
//objDALPlanningModule._dtLOVDescription=clientids;
//dscolor=objDALPlanningModule.GetParaMeterDetailsDAL();
//if (dscolor.Tables[0] != null)
//{
// setcolor = Convert.ToString(dscolor.Tables[0].Rows[0]["Value"]);
//}
//else
//{
//break
//}

if (clientids == "Test Value1")
{
setcolor = "GREEN";
}
else
if (clientids == "Testy Value2")
{
setcolor = "ORANGE";
}
else
{
setcolor = "RED";
}
}
else
{
setcolor = "Aqua";
}


//color and fill clients
for (int i = from; i <= from; i++)
{LinkButton lkBtn = new LinkButton();
lkBtn.ForeColor = Color.Black;
lkBtn.Font.Underline = false;
lkBtn.ID = "link_button" + i;
lkBtn.Text = clientids;
lkBtn.CommandArgument = "link_button"+i;
lkBtn.CommandName = "Edit";
lkBtn. önClientClick = "Edit";
HiddenField hdndate = new HiddenField();
hdndate.ID = "hdn" + i;
hdndate.Value = dateofcell;
e.Row.Cells[i].Controls.Add(hdndate);
e.Row.Cells[i].BackColor = Color.FromName(setcolor);
e.Row.Cells[i].Controls.Add(lkBtn);
}
}

}
//hide other extra created rows
for (int i = 1; i < grid_planningStaff.Rows.Count; i++)
{
grid_planningStaff.Rows[0].Visible = true;
grid_planningStaff.Rows[i].Visible = false;

}
}


eventcode :
protected void grid_planning_OnRowCommand(object sender,
ChintanShukla 27-Aug-14 5:54am    
Is this a new question? or you have already posted? if so provide link
You have to build one DataTable for this.

Declare new DataTable. Then run a loop for all the days and add column for each inside the loop.
Now after adding the columns, add rows.

Then assign the DataTable to the GridView.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900