datalist selectedindexchanged 未触发
页面加载:
protected void Page_Load(object sender, EventArgs e)
{
tb.Columns.Add("Id", typeof(int));
tb.Columns.Add("FileName", typeof(string));
tb.Columns.Add("FilePath", typeof(string));
tb.Columns.Add("Index", typeof(int));
newtb.Columns.Add("Id", typeof(int));
newtb.Columns.Add("FileName", typeof(string));
newtb.Columns.Add("FilePath", typeof(string));
newtb.Columns.Add("Index", typeof(int));
path = objGetBaseCase.GetAllImagesfromGroup(CaseId);
for (int i = 0; i < path.Count; i++)
{
ArrayList alst = path[i];
tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
msgError.Text = "";
dlstImage.DataSource = tb;
DataBind();
List<ArrayList> t = new List<ArrayList>();
if (newpath.Count > 0)
{
t = newpath;
newpath = t;
for (int i = 0; i < newpath.Count; i++)
{
ArrayList alst = newpath[i];
newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
ViewState["tempimage"] = newpath;
dlstSelectedImages.DataSource = newtb;
DataBind();
}
}
Datalist SelectedIndexChanged:
protected void dlstSelectedImages_SelectedIndexChanged(object sender, EventArgs e)
{
indexId = Convert.ToInt32(dlstSelectedImages.DataKeys[dlstSelectedImages.SelectedIndex]);
}
DataList:
<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
RepeatColumns="5" CellSpacing="8" DataKeyField="Id" OnSelectedIndexChanged="dlstSelectedImages_SelectedIndexChanged">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
CommandName="Select" OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
<asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlstSelectedImages.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
尝试使用:View State =“Enable”
,AutoEventWireup =“true”
,
autopostback="true"
当我在其中绑定数据列表时,它运行良好!IsPostBack 但现在我不想在 !IsPostBack 中绑定我的数据列表,我也不想使用 ItemCommand
但它不起作用,有人帮助我...
Page Load:
protected void Page_Load(object sender, EventArgs e)
{
tb.Columns.Add("Id", typeof(int));
tb.Columns.Add("FileName", typeof(string));
tb.Columns.Add("FilePath", typeof(string));
tb.Columns.Add("Index", typeof(int));
newtb.Columns.Add("Id", typeof(int));
newtb.Columns.Add("FileName", typeof(string));
newtb.Columns.Add("FilePath", typeof(string));
newtb.Columns.Add("Index", typeof(int));
path = objGetBaseCase.GetAllImagesfromGroup(CaseId);
for (int i = 0; i < path.Count; i++)
{
ArrayList alst = path[i];
tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
msgError.Text = "";
dlstImage.DataSource = tb;
DataBind();
List<ArrayList> t = new List<ArrayList>();
if (newpath.Count > 0)
{
t = newpath;
newpath = t;
for (int i = 0; i < newpath.Count; i++)
{
ArrayList alst = newpath[i];
newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
ViewState["tempimage"] = newpath;
dlstSelectedImages.DataSource = newtb;
DataBind();
}
}
Datalist SelectedIndexChanged:
protected void dlstSelectedImages_SelectedIndexChanged(object sender, EventArgs e)
{
indexId = Convert.ToInt32(dlstSelectedImages.DataKeys[dlstSelectedImages.SelectedIndex]);
}
DataList:
<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
RepeatColumns="5" CellSpacing="8" DataKeyField="Id" OnSelectedIndexChanged="dlstSelectedImages_SelectedIndexChanged">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
CommandName="Select" OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
<asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlstSelectedImages.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
Itried with: View State="Enable"
, AutoEventWireup="true"
,
autopostback="true"
It was working well when i was binding the datalist inside this !IsPostBack but now I don't want to bind my datalist inside the !IsPostBack and I don't want to use ItemCommand as well
But its not working, someone help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每当触发
SelectedIndex
Change 事件时,都会在selectedIndex
Change 事件之前调用Page_Load
事件。在您的 page_load 事件中,您的DataList
再次绑定,因此您的 SelectedIndex 事件丢失。您必须将 DataList 绑定代码放在!IsPostBack
下,例如Whenever the
SelectedIndex
Change event fires, thePage_Load
event is called before theselectedIndex
Change event. In your page_load event, yourDataList
binded again and hence your SelectedIndex event was lost. You have to put your DataList binding code under!IsPostBack
e.g.您必须在项目模板中放置一个按钮或超链接。
看这里
You have to put in the item template a button or a hyperlink.
Look here