Getting values from another control in a datalist

  • Thread starter Thread starter Regan
  • Start date Start date
R

Regan

So, I have DatalistA on my form; it is rebinding with a refreshed datasetB
after each post back.

DatalistA contains buttonC and labelD, bound to datasetB.

What do I have to do in the OnClick event of buttonC, to retrieve the text
value of labelD?

Thank for your help!
 
Instead of handling OnClick event for the button, handle ItemCommand event
for the datalist:<asp:DataList
OnItemCommand="Item_Command"><ItemTemplate><asp:Button CommandName="XXX"
/></ItemTemplate></asp:DataList>

and in the code behind:
void Item_Command(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "XXX")
string label = (e.Item.FindControl("labelD") as Label).Text;
}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Thanks Eliyahu =)

I appreciate the help. I will explore this soon.

Eliyahu Goldin said:
Instead of handling OnClick event for the button, handle ItemCommand event
for the datalist:<asp:DataList
OnItemCommand="Item_Command"><ItemTemplate><asp:Button CommandName="XXX"
/></ItemTemplate></asp:DataList>

and in the code behind:
void Item_Command(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "XXX")
string label = (e.Item.FindControl("labelD") as Label).Text;
}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Regan said:
So, I have DatalistA on my form; it is rebinding with a refreshed
datasetB after each post back.

DatalistA contains buttonC and labelD, bound to datasetB.

What do I have to do in the OnClick event of buttonC, to retrieve the
text value of labelD?

Thank for your help!
 
Back
Top