Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Comments
saud_a_k 7-Nov-12 1:09am    
A GridView provides and edit template, You could use that

1 solution

i asuuming that you load your data list like this
ASP.NET
 <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>


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
C#
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;
		}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900