从Datalist获取值 [英] Get the values from Datalist

查看:88
本文介绍了从Datalist获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在datalist中显示值,每行都有复选框,因此在加载页面后,当复选框被更改时,我需要做一些计算,

在标签中存储标识列值并使其显示为false



所以任何人都可以帮助找到标识列值选中复选框的确切行,我将通过oncheckedchange事件进行计算...

Hi,

I am showing the values in datalist and in each row i have checkbox, so after loading the page, when when the checkbox is changed i need to do some calculations,
Storing the identity column values in label and made visible false

so can anyone help to find the identity column value at which exact row the checkbox is checked,i would do the calculation by oncheckedchange event...

推荐答案

1。遍历所有datalist项目。

2.在datalist项目上使用FindControl方法获取讨论中的复选框

3.检查是否已选中。如果是,则再次使用FindControl获取隐藏的标签值。



试试!



更新:

尝试类似......

1. Loop through all the datalist items.
2. Use FindControl method on datalist item to get the checkbox in discussion
3. Check if it is checked or not. In case it is, then use FindControl again to get the hidden label value.

Try!

UPDATE:
Try something like...
int count = dl.Items.Count; 
for (int i = 0; i < count; i++) 
{
  Checkbox chk = dl.Items[i].FindControl("chkID") as Checkbox;
  if(chk.Checked)
  { 
    Label ID = dl.Items[i].FindControl("lblID") as Label; 
    string item = ID.Text; 
    // if more than one is checked, continue the loop and track all the texts. 
    // Like: string selectedItemTexts += ID.Text + ",";
  }
}


LinkBut​​ton btn =(LinkBut​​ton)sender;

DataListItem item = btn .NamingContainer as DataListItem;

Label lbl =(Label)ProductList.Items [item.ItemIndex] .FindControl(lblProductCode);
LinkButton btn = (LinkButton)sender;
DataListItem item = btn.NamingContainer as DataListItem;
Label lbl = (Label)ProductList.Items[item.ItemIndex].FindControl("lblProductCode");


这篇关于从Datalist获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆