LinkBut​​ton中的查询字符串不起作用 [英] Query String in LinkButton not working

查看:59
本文介绍了LinkBut​​ton中的查询字符串不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的aspx页面中我已经在page_load中绑定了我的listview,如下所示,我在页面中也有Linkbutton,在此Linkbutton的click事件中我添加了这个来获取UID并使用UID重定向到另一个名为UserAds.aspx的页面,根据查询sting绑定UserAds.aspx中的anothor ListView但是没有任何事情发生qurey字符串不保存UID,我可以使用会话但是没有用作url应该处理用户ID





  protected   void  LinkBut​​ton1_Click( object  sender,EventArgs e)
{


Response.Redirect( UserAds.aspx?USRST + adsusrnmlbl.Text );

}





 SqlConnection shwadsone =  new  SqlConnection(cs); 
{


// 打开连接
shwadsone.Open();
SqlCommand adsdeCM = new SqlCommand();
// 构建数据适配器
string adsdetSqlSelect = @ SELECT AD。[AdsID]
,AD。[UID ]
,AD。[部分]
,AD。[类别]
,AD。[地址]
,UI。[Logo],[Img],[TeleNum], [电子邮件]
FROM [ads] as AD
JOIN
UserInfo as UI
ON AD。[UID] = UI。[UID]
其中AD.AdsID = @AID
;


adsdeCM.CommandText = adsdetSqlSelect;
adsdeCM.CommandType = CommandType.Text;
adsdeCM.Connection = shwadsone;
adsdeCM.Parameters.AddWithValue( AID,Request.QueryString [ AID]);
SqlDataReader adsdetDR;
adsdetDR = adsdeCM.ExecuteReader();

if (adsdetDR.Read())
{

adsusrnmlbl.Text = adsdetDR [< span class =code-string> UID]。ToString();
adssectlbl.Text = adsdetDR [ Section]。ToString();
adscatelbl.Text = adsdetDR [ 类别]。ToString();
adsdetaddrslbl.Text = adsdetDR [ Address]。ToString();
}
}

解决方案

您必须仔细了解应如何构建URL编码(查询字符串)。 ..

http://en.wikipedia.org/wiki/Query_string [ ^ ]

 Response.Redirect(  UserAds.aspx?USRST  =  + adsusrnmlbl 。文本);  //  寻找等号(=)!!!  


Hi
in my aspx page i have bind my listview in page_load as below, and i have Linkbutton also in the page and inside the click event of this Linkbutton i have add this to get the UID and redirect to another page called "UserAds.aspx" with UID to bind anothor ListView in "UserAds.aspx" depending on query sting but nothing is happen the qurey string dont save the UID, I can use a session but that not usefull as the url should handle the user id


protected void LinkButton1_Click(object sender, EventArgs e)
        {
          

                    Response.Redirect("UserAds.aspx?USRST" + adsusrnmlbl.Text);

        }



SqlConnection shwadsone = new SqlConnection(cs);
            {
                

                // Open your connection
                shwadsone.Open();
                SqlCommand adsdeCM = new SqlCommand();
                // Build your data adapter
                string adsdetSqlSelect = @"SELECT AD.[AdsID]
,AD.[UID]
,AD.[Section]
,AD.[Category]
,AD.[Address] 
,UI.[Logo],[Img],[TeleNum],[Email] 
FROM [ads] as AD
JOIN
UserInfo as UI
ON AD.[UID] = UI.[UID]
where AD.AdsID = @AID ";

               
                adsdeCM.CommandText = adsdetSqlSelect;
                adsdeCM.CommandType = CommandType.Text;
                adsdeCM.Connection = shwadsone;
                adsdeCM.Parameters.AddWithValue("AID", Request.QueryString["AID"]);
                SqlDataReader adsdetDR;
                adsdetDR = adsdeCM.ExecuteReader();
                
                if (adsdetDR.Read())
                {

                  adsusrnmlbl.Text = adsdetDR["UID"].ToString();
                  adssectlbl.Text = adsdetDR["Section"].ToString();
                  adscatelbl.Text = adsdetDR["Category"].ToString();
                  adsdetaddrslbl.Text = adsdetDR["Address"].ToString();
                    }
                }

解决方案

You have to learn carefully how URL encoding (query string) should be built...
http://en.wikipedia.org/wiki/Query_string[^]

Response.Redirect("UserAds.aspx?USRST=" + adsusrnmlbl.Text); // look for the equal sign (=)!!!


这篇关于LinkBut​​ton中的查询字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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