I need code example please.i tried selectedindexchange but it doesnot register any index change what to use?
its c# vs08 asp.net sql server
the code files are
.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{//not this
///Label3.Text = "clicked clicked clicked";
}
protected void Button1_Click1(object sender, EventArgs e)
{
Label5.Text = "the tool tip of the button clicked is! HELP!!!";
//here code please how to which button is clicked?
//there are many records so?
//even if i try to use the button id directly
//it does not appear
//to vs the button does not exist outside the datalist control
//help
}
}
the source file
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:test1 %>"
DeleteCommand="DELETE FROM [1] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [1] ([ID], [NAME]) VALUES (@ID, @NAME)"
SelectCommand="SELECT * FROM [1]"
UpdateCommand="UPDATE [1] SET [NAME] = @NAME WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="NAME" Type="String" />
<asp:Parameter Name="ID" Type="Decimal" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Decimal" />
<asp:Parameter Name="NAME" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<asp:DataList ID="DataList2" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource3">
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
<br />
NAME:
<asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
-<asp:Label ID="Label2" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
<br />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text='<%# Eval("ID") %>'
ToolTip='<%# Eval("NAME") %>'></asp:Label>
<br />
here extra information/ description is binded to tool tip.<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
Text='<%# Eval("ID") %>' ToolTip='<%# Eval("NAME") %>' />
<br />
when clicked, the text of the button is displayed in the label. but many records
so button belonging to which record clicked?<br />
<br />
<br />
<hr />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<br />
EDIT
<asp:DataList ID="DataList2" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource3">
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
<br />
NAME:
<asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
-<asp:Label ID="Label2" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
<br />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text='<%# Eval("ID") %>'
ToolTip='<%# Eval("NAME") %>'></asp:Label>
<br />
here extra information/ description is binded to tool tip.<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
Text='<%# Eval("ID") %>' ToolTip='<%# Eval("NAME") %>' />
<br />
when clicked, the text of the button is displayed in the label. <br />
<br />
<br />
<asp:Button ID="Button2" runat="server" CommandArgument='<%# Eval("NAME") %>'
CommandName="Explain" Text='<%# Eval("ID") %>' />
<asp:TextBox ID="TextBox1" runat="server">First Record</asp:TextBox>
<br />
when clicked takes argument from button and the text in the text box, displayed.
(record 1)<br />
<br />
<br />
<br />
<asp:Button ID="Button3" runat="server" CommandArgument='<%# Eval("NAME") %>'
CommandName="Explain" Text='<%# Eval("ID") %>' />
//<br />
when clicked does the same as above
<br />
<hr />
<br />
<br />
</ItemTemplate>
</asp:DataList>
code behind
protected void DataList2_ItemCommand(object sender, DataListCommandEventArgs e) { // all of the buttons within the row that have the CommandName property set can cause this event handler to execute. // Use the CommandName argument to determine which button was clicked and take the appropriate action switch (e.CommandName) {
case "Explain":
// update your label using the command argument rather that the button's ToolTip
Label5.Text = e.CommandArgument.ToString();
TextBox TextBox1 = e.Item.FindControl("TextBox1") as TextBox;
Label6.Text = TextBox1.Text;
break;
default:
Label5.Text="ERROR";
break;
}
}
mistake:- i forgot to put OnItemCommand="MyDataList_ItemCommand" in datalist source code ...