Reapeter Control and Array List

  • Thread starter Thread starter Shawn H. Mesiatowsky
  • Start date Start date
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
 
you can use the button control and use reflection to get the instance and
add the onclick attribute to it then. Something like

if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item )
{
Button ib = (Button)e.Item.FindControl("DeleteButton");
ib.Attributes.Add("onclick","DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() + ")";
}


MattC


Shawn H. Mesiatowsky said:
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
 
Tried that, but the output from the button control makes it type=submit so a
clientside script to use window.navigate('someurl.htm'); will not work

MattC said:
you can use the button control and use reflection to get the instance and
add the onclick attribute to it then. Something like

if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item )
{
Button ib = (Button)e.Item.FindControl("DeleteButton");
ib.Attributes.Add("onclick","DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() + ")";
}


MattC


Shawn H. Mesiatowsky said:
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
 
You could use an Image button, they look nicer too!

MattC
Shawn H. Mesiatowsky said:
Tried that, but the output from the button control makes it type=submit so
a clientside script to use window.navigate('someurl.htm'); will not work

MattC said:
you can use the button control and use reflection to get the instance
and add the onclick attribute to it then. Something like

if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item )
{
Button ib = (Button)e.Item.FindControl("DeleteButton");
ib.Attributes.Add("onclick","DeleteEntry(" +
((int)DataBinder.Eval(e.Item.DataItem,"UserID")).ToString() + ")";
}


MattC


Shawn H. Mesiatowsky said:
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
 
Back
Top