Datalist按钮单击事件 [英] Datalist Button Click Event

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

问题描述

我有一个带有1个按钮的数据列表,但是根据返回的记录数量,我想使用Response.Redirect来确定在下一页上将选择哪个查询字符串。这是一个例子。在按钮clcik事件上我有。



I have a datalist with 1 button, but depending on how many records are returned i would like to use Response.Redirect to determine which query string will paear on the following page. Here is an example. On the button clcik event I have.

protected void InstallChecklist_TW_Click(object sender, EventArgs e)
    {
        string Install1Name_TW = ((Label)DataList1.Items[0].FindControl("InstallName_TW")).Text;
               
          Response.Redirect("tespage.aspx?InstallName_TW=" + Install1Name_TW);

     }





这按预期工作并传递查询字符串。所以我想这将是我的datalist按钮索引0和我的datalist标签索引0.但是,有时会有多个记录,我将需要传递按钮索引1和标签索引1的查询字符串,依此类推。如何做到这一点。



有没有办法我可以说如果按下按钮索引1就这样做等等......?



先谢谢。



This works as expected and passes the querystring. So I guess this would be for my datalist button index 0 and my datalist label index 0. However, at times there will be more than one record and I will need to pass the querystring for button index 1 and label index 1 and so on. How can this be done.

Is there a way That I can say if button index 1 is pressed do this and so on..?

Thanks In Advance.

推荐答案

protected void InstallChecklist_TW_Click(object sender, EventArgs e)
    {
       string sUrl = String.Empty;
       foreach(DataListItem item in DataList1.Items)
       {
            if(item is Label)
            {
             Label lbl = (Label)item;
             sUrl += "&" + lbl.Text + "=" lbl.Text;
            }
       }
       sUrl = sUrl.TrimStart('&');
       Response.Redirect("tespage.aspx?" + sUrl);
     }


我最终使用以下代码:



I ended up using the following code:

DataListItem item = (sender as Button).NamingContainer as DataListItem;
string str1 = (item.FindControl("InstallName_TW") as Label).Text;
Response.Redirect("tespage.aspx?InstallName_TW=" + str1);





感谢大家的帮助!



Thanks everyone for the help!


这篇关于Datalist按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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