When design I have a Datalist with a label inside. when load it will has 10 label(datasource from list has 10 value type int ). I want get value of any label which i click. I think i must resolve 2 problem:
1. Find control(label inside datalist) which is clicked.
2. Get value of it.
protected void Page_Load(object sender, EventArgs e)
{
List<int> list = new List<int>();
for (int i = 0; i < 10; i++)
{
list.Add(i);
}
int a=1;
DataList1.DataSource = list;
DataList1.DataBind();
foreach (DataListItem item in DataList1.Items)
{
((Label)item.FindControl("Label1")).Text = a.ToString();
if ((Convert.ToInt32(((Label)item.FindControl("Label1")).Text)) % 2 != 0)
{
((Label)item.FindControl("Label1")).BackColor = System.Drawing.Color.Gray;
}
((Label)item.FindControl("Label1")).Attributes.Add("onclick", "run();");
a++;
}
This is my run() function
function run() {
$("#Panel1").scrollTop(100*gt1);
}
Here, i want gt1 get value of label clicked.
Thanks for helping(sr about my English)
Try it this way…
We will pass the current object of label while binding javascript event with it using keyword this. on server side
On Client side we have to change the definition to receive a parameter which is passed from server side. In our case parameter name is lbl.
This is nice article will give you good understanding of grid view here