在 page_init 或 page_load 时触发转发器控件的哪个事件?
我有一个像 Facebook 墙这样的场景,我需要在中继器控件中显示发帖者的图像。
我已尝试 myrepeater_ItemCommand1
或 myrepeater_ItemDataBound
但不起作用。
后面的代码
protected void myrepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
try
{
LinkButton lblPostedBy = (LinkButton)e.Item.FindControl("lblPostedBy");
con.Open();
cmd.CommandText = "select image from " + lblPostedBy.Text + " where id=1";
cmd.Connection = con;
string imageurl = (string)cmd.ExecuteScalar();
con.Close();
Image Image1 = (Image)e.Item.FindControl("Image1");
Image1.ImageUrl = imageurl;
}
catch (Exception a)
{
lblMsg.Text = a.Message;
msgbox.Visible = true;
}
}
与 myrepeater_ItemCommand1
中的代码相同,如果我单击 Repeater 内的按钮,该代码就会起作用。
我想知道在 Page_Load
或 Page_Init
时触发 Repeater control
的哪个事件。
或者,请建议我其他方式来完成我的任务。
顺便说一句,我的项目是使用 C# ASP.NET 4
编写的。
I have a scenario like facebook wall where I need to display image of user in repeater control who posted.
I have tried myrepeater_ItemCommand1
or myrepeater_ItemDataBound
but not working.
Code behind
protected void myrepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
try
{
LinkButton lblPostedBy = (LinkButton)e.Item.FindControl("lblPostedBy");
con.Open();
cmd.CommandText = "select image from " + lblPostedBy.Text + " where id=1";
cmd.Connection = con;
string imageurl = (string)cmd.ExecuteScalar();
con.Close();
Image Image1 = (Image)e.Item.FindControl("Image1");
Image1.ImageUrl = imageurl;
}
catch (Exception a)
{
lblMsg.Text = a.Message;
msgbox.Visible = true;
}
}
and same in myrepeater_ItemCommand1
which is working if I click button inside Repeater.
I wanted to know that which event of Repeater control
fires at the time of Page_Load
or Page_Init
.
Or, kindly suggest me other way to accomplish my task.
BTW, my project is in C# ASP.NET 4
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保存帖子后,您应该重新绑定中继器。重新绑定中继器后,应该会显示您的更新。
编辑
并在后面的代码中:
更新后:
After the post has been saved, you should rebind the repeater. After rebinding the repeater, your updates should display.
EDIT
And in the code behind:
After an update: