How to update querystring in C#?

后端 未结 11 1251
野的像风
野的像风 2020-12-02 12:06

Somewhere in the url there is a &sortBy=6 . How do I update this to &sortBy=4 or &sortBy=2 on a button click? Do I need to write custom string functions to creat

11条回答
  •  鱼传尺愫
    2020-12-02 12:58

    Retrieve the querystring of sortby, then perform string replace on the full Url as follow:

    string sUrl = *retrieve the required complete url*
    string sCurrentValue = Request.QueryString["sortby"];
    sUrl = sUrl.Replace("&sortby=" + sCurrentValue, "&sortby=" + newvalue);
    

    Let me know how it goes :)

    Good luck

提交回复
热议问题