S
Shawn H. Mesiatowsky
I have an array list that I want to display to the browser. I need very
precise control of the repeater, so I have function for the OnItemDataBound
event for the repater, then in that function I have my code to alter the
displayed data. for instance, I need to display a button on the client side
with client side script. I cannot accomplish this using the Button web
control, so instead I use a label and in the text of the label I set it to
((Label)e.Item.FindControl("DeleteButton")).Text="<button
onclick='DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() +
")'>Delete</button>";
Here is my code
private void Page_Load(object sender, System.EventArgs e)
{
ProjectProcess businessLogic = new ProjectProcess();
double SIDID = double.Parse(Request.Params["id"]);
ArrayList securityEntries;
securityEntries = businessLogic.listSecurityEntries(SIDID);
Repeater1.DataSource = securityEntries;
Repeater1.DataBind();
}
public void repeater1ItemDataBound(Object source,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
((HyperLink)e.Item.FindControl("lblUser")).Text =
(string)DataBinder.Eval(e.Item.DataItem,"UserName");
((HyperLink)e.Item.FindControl("lblUser")).NavigateUrl =
"Security.aspx?user=" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString();
((Label)e.Item.FindControl("DeleteButton")).Text="<button
onclick='DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() +
")'>Delete</button>";
}
}
The client side code for the DeleteEntry function is as follows:
function DeleteMe(userid)
{
if(confirm("Are you sure you want to delete the record?"))
{
window.location="Security.aspx?command=delete&user=" + userid;
}
return;
}
Anywayz, I thought to myself, if I just create on label, and in the label,
change the text in code to display what I want instead of using a repeater
control all together. This would be much like using the old ASP model and
using the reponse.write method where I wanted to display the data. the only
difference here is that I cannot use the reponse.write function here because
I would be writing to the end of my reponse html code returned to the
client. I know there is a performance hit with calling the OnItemDataBound
event. Would the method I just described be less of a performance hit, or is
there another way of looking at this? Thanks
precise control of the repeater, so I have function for the OnItemDataBound
event for the repater, then in that function I have my code to alter the
displayed data. for instance, I need to display a button on the client side
with client side script. I cannot accomplish this using the Button web
control, so instead I use a label and in the text of the label I set it to
((Label)e.Item.FindControl("DeleteButton")).Text="<button
onclick='DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() +
")'>Delete</button>";
Here is my code
private void Page_Load(object sender, System.EventArgs e)
{
ProjectProcess businessLogic = new ProjectProcess();
double SIDID = double.Parse(Request.Params["id"]);
ArrayList securityEntries;
securityEntries = businessLogic.listSecurityEntries(SIDID);
Repeater1.DataSource = securityEntries;
Repeater1.DataBind();
}
public void repeater1ItemDataBound(Object source,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
((HyperLink)e.Item.FindControl("lblUser")).Text =
(string)DataBinder.Eval(e.Item.DataItem,"UserName");
((HyperLink)e.Item.FindControl("lblUser")).NavigateUrl =
"Security.aspx?user=" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString();
((Label)e.Item.FindControl("DeleteButton")).Text="<button
onclick='DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() +
")'>Delete</button>";
}
}
The client side code for the DeleteEntry function is as follows:
function DeleteMe(userid)
{
if(confirm("Are you sure you want to delete the record?"))
{
window.location="Security.aspx?command=delete&user=" + userid;
}
return;
}
Anywayz, I thought to myself, if I just create on label, and in the label,
change the text in code to display what I want instead of using a repeater
control all together. This would be much like using the old ASP model and
using the reponse.write method where I wanted to display the data. the only
difference here is that I cannot use the reponse.write function here because
I would be writing to the end of my reponse html code returned to the
client. I know there is a performance hit with calling the OnItemDataBound
event. Would the method I just described be less of a performance hit, or is
there another way of looking at this? Thanks