Creation of repeater dynamically.

Jaggi237
Posted by Jaggi237 under C# category on | Points: 40 | Views : 849
public void DynamicRepeater()
{
dv.Controls.Clear();
Repeater rpt = new Repeater();
rpt.ItemDataBound += rptr_ItemDataBound;
rpt.DataSource = lstAllActivity
rpt.DataBind();
rpt.EnableViewState = false;
dv.Controls.Add(rpt);
}
else
{
rpt.DataSource = null;
rpt.DataBind();
}
}

protected void rptr_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ActivityMasterEntity act = (e.Item.DataItem as ActivityMasterEntity);
RepeaterItem repeaterItem = new RepeaterItem(e.Item.ItemIndex, ListItemType.Item);
LiteralControl lblBegin = new LiteralControl();
LiteralControl lblEnd = new LiteralControl();
Repeater rpt = new Repeater();
rpt.ID = "rpt";
hdnActivityId.Value = act.ActivityId.ToString();
LinkButton dynamicLnkAddButton = CreateDynamicAddLnkBotton();
LinkButton dynamicLnkRemoveButton = CreateDynamicRemoveLnkBotton();
lblBegin.Text = "<div style='padding-top:5px; padding-bottom:5px; padding-left:75px; border:1px #8f989c Solid; white-space: nowrap!important; overflow: hidden!important; text-overflow: ellipsis!important;' class='col-md-12'>" + act.ActivityDescription + "</br>";
lblEnd.Text = "</div>";
List<ActivityMasterEntity> lstAct = lstAllActivity.FindAll(x => x.ParentId == act.ActivityId);
rpt.ItemDataBound += rptr_ItemDataBound;
rpt.DataSource = lstAct;
rpt.DataBind();
repeaterItem.Controls.Add(lblBegin);
repeaterItem.Controls.Add(dynamicLnkAddButton);
repeaterItem.Controls.Add(dynamicLnkRemoveButton);
repeaterItem.Controls.Add(rpt);
repeaterItem.Controls.Add(lblEnd);
e.Item.Controls.Add(repeaterItem);
}
}

private LinkButton CreateDynamicAddLnkBotton()
{
LinkButton dynamicAddLnkButton = new LinkButton();
dynamicAddLnkButton.ID = "btnAddSubItems" + "$" + hdnActivityId.Value;
dynamicAddLnkButton.CommandName = "AddSubActivities";
dynamicAddLnkButton.CommandArgument = hdnActivityId.Value;
dynamicAddLnkButton.CssClass = "btn btn-success btn-xs glyphicon glyphicon-plus";
dynamicAddLnkButton.Style["Position"] = "Absolute";
dynamicAddLnkButton.Style["Left"] = "10px";
return dynamicAddLnkButton;
}

private LinkButton CreateDynamicRemoveLnkBotton()
{
LinkButton dynamicRemoveLnkButton = new LinkButton();
dynamicRemoveLnkButton.ID = "btnRemoveSubItems" + "$" + hdnActivityId.Value;
dynamicRemoveLnkButton.CommandName = "RemoveSubActivities";
dynamicRemoveLnkButton.CssClass = "btn btn-danger btn-xs glyphicon glyphicon-remove";
dynamicRemoveLnkButton.Style["Position"] = "Absolute";
dynamicRemoveLnkButton.Style["Left"] = "35px";
return dynamicRemoveLnkButton;
}

Comments or Responses

Login to post response