I have a RadGrid (Q3 2010).
I want to dynamic create GridView Column and Row, so I create A template like that :
It mean , I have a template Control and Header Template of it is Table Control. And Item Template of it also is table.
I create Session Variable .
Okie , In PageLoad Event I bind data for grid.
In RadGrid DataItem Bound event, I create dynamic data and add each cell of table ( Is Template of control). If room is used , CheckBox and Lable of status ' room is bound, else the Empty Lable is bound.(Don't care about the content of code, I just demo)
I have a RadDatePicker to choose day which find Date from RadDatePicker and fill Data in the form.
I have a button, when you click it, all checked CheckBox control in Item Template will select. After that , control will delete in database (like that)
Every thing is okie , if you don't select day from RadDatePicker.
But If you selecte date from RadDatePicker, control will rebind TimeTable.And when you click to button, every check-box status is unchecked.
I spend a lot of time in the internet, but I can't find reason.
Please help me. My project is very urgent. This control must be release in the next week.
Tell me why and how to fix it,please .
I want to dynamic create GridView Column and Row, so I create A template like that :
<telerik:RadGrid ID="rgView" runat="server" AutoGenerateColumns="False" GridLines="None" OnItemDataBound="rgView_ItemDataBound"> <MasterTableView> <Columns> <telerik:GridTemplateColumn> <HeaderTemplate><br> <asp:Table ID="tblHeaderItem" runat="server"> </asp:Table> </HeaderTemplate> <ItemTemplate> <asp:Table ID="tblItem" runat="server"> </asp:Table> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>It mean , I have a template Control and Header Template of it is Table Control. And Item Template of it also is table.
I create Session Variable .
public DataView dv { get { return Session["AllControl_Academic_BookActivity_View_View_dv"]==null?null:(DataView)(Session["AllControl_Academic_BookActivity_View_View_dv"]); } set { Session["AllControl_Academic_BookActivity_View_View_dv"] = value; } }Okie , In PageLoad Event I bind data for grid.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindTimeTable(); } }
private void BindTimeTable() { dv = new DataView(learningActivityModal.GetInformationAboutBooking((DateTime)this.rdpBookingDate.SelectedDate, SimpleWebSessionManagement.CurrentBranches, SimpleWebSessionManagement.CurrentTrainningProgram));//It just binddata DataTable workTable = new DataTable(); workTable.Columns.Add("RoomName", typeof(String)); DataRow row = workTable.NewRow(); row[0] = ""; workTable.Rows.Add(row); this.rgView.DataSource = workTable; this.rgView.DataBind(); }In RadGrid DataItem Bound event, I create dynamic data and add each cell of table ( Is Template of control). If room is used , CheckBox and Lable of status ' room is bound, else the Empty Lable is bound.(Don't care about the content of code, I just demo)
protected void rgView_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item.ItemType == GridItemType.Header) { Table tblHeader = e.Item.FindControl("tblHeaderItem") as Table; tblHeader.Width = new Unit("100%"); TableRow tblRow = new TableRow(); tblRow.Width = new Unit("100%"); TableCell tblCell = new TableCell(); tblCell.HorizontalAlign = HorizontalAlign.Left; tblCell.Width = new Unit("10%"); Label lblHeader = new Label(); lblHeader.Text = ""; tblCell.Controls.Add(lblHeader); tblRow.Cells.Add(tblCell); for (int i = 0; i < dtProgramSlot.Rows.Count; i++) { tblCell = new TableCell(); tblCell.HorizontalAlign = HorizontalAlign.Left; lblHeader = new Label(); lblHeader.Text = dtProgramSlot.Rows[i]["SlotName"].ToString() + "<br/> (" + dtProgramSlot.Rows[i]["StartTime"].ToString() + " - " + dtProgramSlot.Rows[i]["EndTime"].ToString() + ")"; tblCell.Controls.Add(lblHeader); tblRow.Cells.Add(tblCell); } tblHeader.Rows.Add(tblRow); } if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) { Table tblItem = e.Item.FindControl("tblItem") as Table; tblItem.Width = new Unit("100%"); TableRow tblRow; TableCell tblCell; int scale = (int)(90 / dtProgramSlot.Rows.Count); for (int i = 0; i < dtRoom.Rows.Count; i++) { //Add Rooms tblRow = new TableRow(); tblRow.Width = new Unit("100%"); tblCell = new TableCell(); tblCell.BorderWidth = 1; tblCell.HorizontalAlign = HorizontalAlign.Left; tblCell.Width = new Unit("10%"); Label lblHeader = new Label(); lblHeader.Text = dtRoom.Rows[i]["RoomName"].ToString(); tblCell.Controls.Add(lblHeader); tblRow.Cells.Add(tblCell); //Add Infor for (int j = 0; j < dtProgramSlot.Rows.Count; j++) { dv.RowFilter = "RoomName = '" + dtRoom.Rows[i]["RoomName"].ToString() + "' and SlotsId =" + dtProgramSlot.Rows[j]["SlotsId"].ToString(); tblCell = new TableCell(); tblCell.Width = new Unit(scale.ToString()+"%"); tblCell.HorizontalAlign = HorizontalAlign.Left; if (dv.Count > 0) { DataTable dtInfor = dv.ToTable(true); string strInfor, strGroups = ""; strInfor = dtInfor.Rows[0]["CourseName"].ToString() + "<br/>" + dtInfor.Rows[0]["UserName"].ToString() + "<br/>"; for (int k = 0; k < dtInfor.Rows.Count; k++) { strGroups += dtInfor.Rows[k]["GroupName"].ToString() + "<br/>,"; } strGroups = strGroups.Substring(0, strGroups.Length - 1); strInfor += strGroups; RoomSlot rs = new RoomSlot(); CheckBox chkSelected = new CheckBox(); chkSelected.ID = "chkSelected" + Index.ToString(); rs.Index = Index; rs.RoomId = i; rs.SlotId = j; rs.TermId = StringUtil.IsNullOrEmpty(dtInfor.Rows[0]["TermId"]) ? -1 : int.Parse(dtInfor.Rows[0]["TermId"].ToString()); rs.CourseId = Int32.Parse(dtInfor.Rows[0]["CourseId"].ToString()); this.lstRoomSlot.Add(rs); Index++; tblCell.Controls.Add(chkSelected); Label lb = new Label(); lb.BorderStyle = BorderStyle.None; lb.Text = strInfor; //lb.Attributes["style"] += "cursor:pointer;cursor:hand;"; string msg = ""; msg += "brandid=" + SimpleWebSessionManagement.CurrentBranches + "&"; msg += "programid=" + SimpleWebSessionManagement.CurrentTrainningProgram + "&"; msg += "termid=" + dtInfor.Rows[0]["TermId"].ToString() + "&"; msg += "courseid=" + dtInfor.Rows[0]["CourseId"].ToString() + "&"; msg += "areaid=" + this.AreaId + "&"; msg += "bookdate=" + rdpBookingDate.SelectedDate.Value.ToShortDateString() + "&"; msg += "slotid=" + dtProgramSlot.Rows[j]["SlotsId"].ToString() + "&"; msg += "roomid=" + dtRoom.Rows[i]["id"].ToString() + "&"; msg += "lecturer=" + dtInfor.Rows[0]["UserName"].ToString() + "&"; msg += "courseslot=" + dtInfor.Rows[0]["Course_Slot"].ToString() + "&"; msg += "groups=" + strGroups; lb.BackColor = Color.Transparent; lb.ForeColor = Color.Red; tblCell.Controls.Add(lb); rs.Update = ""; rs.Update += "brandid=" + SimpleWebSessionManagement.CurrentBranches + "&"; rs.Update += "programid=" + SimpleWebSessionManagement.CurrentTrainningProgram + "&"; rs.Update += "termid=" + dtInfor.Rows[0]["TermId"].ToString() + "&"; rs.Update += "courseid=" + dtInfor.Rows[0]["CourseId"].ToString() + "&"; rs.Update += "areaid=" + this.AreaId + "&"; rs.Update += "bookdate=" + rdpBookingDate.SelectedDate.Value.ToShortDateString() + "&"; rs.Update += "slotid=" + dtProgramSlot.Rows[j]["SlotsId"].ToString() + "&"; rs.Update += "roomid=" + dtRoom.Rows[i]["id"].ToString() + "&"; rs.Update += "lecturer=" + dtInfor.Rows[0]["UserName"].ToString() + "&"; rs.Update += "groups=" + strGroups; this.lstRoomSlot.Add(rs); } else { Label lb = new Label(); lb.ForeColor = Color.Green; lb.Text = "Đang trống"; tblCell.Controls.Add(lb); } tblRow.Cells.Add(tblCell); } tblItem.Rows.Add(tblRow); } } }I have a RadDatePicker to choose day which find Date from RadDatePicker and fill Data in the form.
<telerik:RadDatePicker ID="rdpBookingDate" runat="server" AutoPostBack="True" OnSelectedDateChanged="rdpBookingDate_SelectedDateChanged"> <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"> </Calendar> <DateInput DisplayDateFormat="M/d/yyyy" DateFormat="M/d/yyyy" AutoPostBack="True"> </DateInput> <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton> </telerik:RadDatePicker>protected void rdpBookingDate_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e) { BindTimeLIne(); }I have a button, when you click it, all checked CheckBox control in Item Template will select. After that , control will delete in database (like that)
public void BtnDelete_Method(object sender,EventArgs e) { lbMessage.Text = string.Empty; GridDataItem item = rgView.Items[0]; for (int i = 0; i < Index; i++) { CheckBox chk = item.FindControl("chkSelected" + i.ToString()) as CheckBox; if (chk != null & chk.Checked) { string msg = learningActivityModal.DelelteObjectData((DateTime)rdpBookingDate.SelectedDate, ReturnValueWithoutException.ReturnInt(dtRoom.Rows[rs.RoomId]["id"]), ReturnValueWithoutException.ReturnInt(dtProgramSlot.Rows[rs.SlotId]["SlotsId"])); if (msg == FixedVariable.DoneOutPutFromDatabaseAsString) lbMessage.Text += "Delete " + dtRoom.Rows[rs.RoomId]["RoomName"].ToString()+" "+dtProgramSlot.Rows[rs.RoomId]["SlotName"].ToString()+"<br/>"; else lbMessage.Text += msg+"<br/>"; } } BindTimeTable(); }Every thing is okie , if you don't select day from RadDatePicker.
But If you selecte date from RadDatePicker, control will rebind TimeTable.And when you click to button, every check-box status is unchecked.
I spend a lot of time in the internet, but I can't find reason.
Please help me. My project is very urgent. This control must be release in the next week.
Tell me why and how to fix it,please .