国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

獲取DataList控件的主鍵和索引實用圖解

2024-07-10 13:18:13
字體:
來源:轉載
供稿:網友
“哈哈,看了這篇,只有效果,但沒有結果,我怎樣獲取選擇行的相關記錄?”

Insus.NET首先多謝網友對上面那篇博文的關注。解決你的問題,可以嘗試獲取選擇行的索引或是主鍵即可,能獲取到主鍵,其它字段的值,也可以獲取到了。

下圖中,高亮選擇區,即是針對問題解決而在原在代碼添加的部分。一是在DataList控件添加一個DataKeyField,以便獲取到它的主鍵值,另外還添加了兩個銨鈕及一個Label標答,用來顯示選擇結果,真正將來你也許用不上標簽,因為獲取到結果之后,就可以進行你想的要事情了。

獲取DataList控件的主鍵和索引實用圖解


兩個銨鈕事件,都是很簡單,Insus.NET相信你能看得懂,如果遇上不明,可以討論:

復制代碼 代碼如下:


View Code
protected void Button1_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
if (FindControl("DataListConstellation") == null) return;
DataList dlconstellation = (DataList)FindControl("DataListConstellation");
foreach (DataListItem dli in dlconstellation.Items)
{
if (dli.FindControl("RadioButtonSelect") == null) return;
RadioButton rb = (RadioButton)dli.FindControl("RadioButtonSelect");
if (rb.Checked)
{
LabelSelectedResult.Text = string.Format("你執行銨鈕'{0}',選擇行的索引是:{1}; 主鍵值是:{2}", button.Text, dli.ItemIndex.ToString(), dlconstellation.DataKeys[dli.ItemIndex].ToString());
break;
}
else
{
LabelSelectedResult.Text = string.Format("你執行銨鈕'{0}',沒有選擇任何一行。", button.Text);
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
DataList dlconstellation = (DataList)FindControl("DataListConstellation");
for (int i = 0; i < dlconstellation.Items.Count; i++)
{
RadioButton rb = (RadioButton)dlconstellation.Items[i].FindControl("RadioButtonSelect");
if (rb.Checked)
{
LabelSelectedResult.Text = string.Format("你執行銨鈕'{0}',選擇行的索引是:{1}; 主鍵值是:{2}", button.Text, i.ToString(), dlconstellation.DataKeys[i].ToString());
break;
}
else
{
LabelSelectedResult.Text = string.Format("你執行銨鈕'{0}',沒有選擇任何一行。", button.Text);
}
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 英山县| 赤壁市| 宝兴县| 朔州市| 临澧县| 汤阴县| 海口市| 中方县| 木里| 十堰市| 巴林左旗| 安多县| 曲麻莱县| 连南| 昌都县| 沙洋县| 黄梅县| 韶山市| 湖南省| 辉县市| 高雄市| 井研县| 南通市| 搜索| 高州市| 闽侯县| 日土县| 广水市| 清水县| 武城县| 神木县| 凤城市| 阿拉善右旗| 府谷县| 阿图什市| 阿拉善盟| 木兰县| 汽车| 东平县| 新沂市| 徐汇区|