2014年7月13日 星期日

[RESOLVED] Is it possible to get data in datalist without using ItemDataBound?


Hi,



in datalist i have control label lblText.



I want to use



LinkButton lnk = (LinkButton)e.Item.FindControl("lnkoValue");



if(lnk.Text=="1500" { lnk.Text="test" })



Is it possible to get without using ItemDataBound this result?



I want to get when i clicked Button1,...



help



You can get it by iterating over the dataList.Items collection and then getting the required control. But for this to work you will have to bind the data list on post back of button click. So on post back the data grid should be rebound so that its state
could be loaded from view state.



thanks.



you have example for this?



Hi programercek,


Please try to refer to the following code:


protected void Button_Click(object sender, EventArgs e)
{

Label lbl = (Label)GridView1.Rows[0].Cells[1].FindControl("labelSubjectID");
//If you want foreach the Rows
foreach (GridViewRow row in GridView1.Rows)
{
Label lblTest = (Label)row.Cells[1].FindControl("labelSubjectID");
}
}

Hope it can help you.


Best Regards,

Terry Guo


沒有留言:

張貼留言