使用ajax编辑转发器 [英] repeater edit using ajax
本文介绍了使用ajax编辑转发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i有一个充满数据的转发器..现在按一下按钮,其中一个数据将显示在灯箱中,然后我可以通过ajax json更新...
任何人都可以告诉我如何从转发器到灯箱获取数据...
谢谢
i have a repeater with full of data..now on a button click one of the data will be shown in the lightbox and then i can update this by ajax json...
can any one tell me how to get the data from repeater to lightbox...
thanks
推荐答案
asp code
asp code
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"
OnItemDataBound="">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ContactName") %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactID") %>'></asp:Label>
<asp:Button ID="Button1" runat="server" Text="view" CommandArgument='<%# Eval("ContactID") %>' CommandName="view" />
<asp:Button ID="Button2" runat="server" Text="view" CommandArgument='<%# Eval("ContactID") %>' CommandName="edit" />
</ItemTemplate>
</asp:Repeater>
<br /><br />
<div id="div1" runat="server" Visible="false" style="background-color: #FF66FF">
<div>
name =
<asp:Label ID="Label1" runat="server" Text="" Visible="false"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox>
<input id="btn1" type="button" value="submit" onclick="return btn1_onclick()" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
cs代码:
cs code :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable table = new DataTable();
table.Columns.Add("ContactID", typeof(int));
table.Columns.Add("ContactName", typeof(string));
//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin");
table.Rows.Add(50, "Enebrel");
table.Rows.Add(10, "Hydralazine");
table.Rows.Add(21, "Combivent");
table.Rows.Add(100, "Dilantin");
Repeater1.DataSource = table;
Repeater1.DataBind();
}
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "view")
{
string la = ((Label)Repeater1.Items[e.Item.ItemIndex].FindControl("Label2")).Text;
//Response.Write("<script>alert('" + la + "');</script>");
Label1.Text = la;
//Label1.Attributes.Add("display","block");
div1.Visible = true;
Label1.Visible = true;
}
else if(e.CommandName=="edit")
{
TextBox1.Text = ((Label)Repeater1.Items[e.Item.ItemIndex].FindControl("Label2")).Text;
//Label1.Attributes.Add("display","block");
div1.Visible = true;
TextBox1.Visible = true;
}
}
现在根据灯箱设计用css ....改变div1。
now change the div1 according to the lightbox design with css....
这篇关于使用ajax编辑转发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文