如何从asp.net中的数据列表访问数据 [英] How to access data from the datalist in asp.net

查看:212
本文介绍了如何从asp.net中的数据列表访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,
我创建了一个应用程序,在其中已给数据列表添加了标签,
文本框,此控件按钮.我的问题是,当我们单击数据列表中存在的按钮时,我想在文本框中显示标签文本..
先生,请给我适当的解决方案..

Respected Sir,
I have create application in which i have given Datalist putting Label,
textbox ,Button this control. My problem is ,when we click on the button which is present in the datalist,I want to show label text into textbox..
Please Sir, Given me proper solution to me..

推荐答案

我假设您像这样加载数据列表
i asuuming that you load your data list like this
 <asp:datalist id="DataList1" runat="server" onselectedindexchanged="DataList1_SelectedIndexChanged">
  <itemtemplate>
	<table class="style1">
	   <tr>
	    <td>
	        <asp:label id="Label1" runat="server" text="<%#Eval("Id") %>"></asp:label>
   </td>
 <td>
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" />
	   </td>
	  </tr>
	</table>
 </itemtemplate>
</asp:datalist>



因此,您单击按钮的代码与此相同,您可以单击数据列表中每一行的按钮,并从文本框中的每一行获取ID



and so you button click will be same this code you can click button in each row in data list and get Id from each row in a textbox

protected void Button1_Click(object sender, EventArgs e)
		{
			Button BuyNowButton = (Button)sender;
                DataListItem item = (DataListItem)BuyNowButton.NamingContainer;
                Label NameLabel = (Label)item.FindControl("label1");
	        TextBox1.Text = NameLabel.Text;
		}


这篇关于如何从asp.net中的数据列表访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆