简体   繁体   English

我如何使用C#从asp.net的querystring中一一删除ID?

[英]How can i remove ids one by one from querystring in asp.net using c#?

I want remove "ids"one by one querystring from my url. 我想从网址中通过一个查询字符串删除“ ids”。 How can i do this ? 我怎样才能做到这一点 ? (using Asp.net4.0 , c#) (使用Asp.net4.0,c#)

Default.aspx?ids=10,2,6,5

I want to remove"ids=6", but language would be the first,middle or last, so I will have this : 我想删除“ ids = 6”,但是语言将是第一个,中间或最后一个,所以我将有以下内容:

Default.aspx?ids=10,2,5,

Step 1. Have your ids in an array by:- 步骤1.通过以下方法将您的ID放在一个数组中:

string[] idsarray = Request.QueryString["ids"].ToString().Split(',');

step 2. create a function to remove as per your language 步骤2.根据您的语言创建删除功能

string removeidat(string[] id, string at)
{
     string toren = "";
     int remat = -1;
     if (at=="first")
     {
          remat = 0;
     }
     else if (at == "middle")
     {
          remat = id.Length / 2;
     }
     else
     {
          remat = id.GetUpperBound(0);
     }
     for (int i = 0; i < id.GetUpperBound(0); i++)
     {
          if (i!=remat)
          {
               toren += id[i] + ",";
          }
     }
     if (toren.Length>0)
     {
          toren = toren.Substring(0, toren.Length - 1);
     }
     return toren;
}

Example : if you want to remove last id your code would be 示例:如果要删除最后一个ID,则代码为

string[] idsarray = Request.QueryString["ids"].ToString().Split(',');
string newids = removeidat(idsarray , "last")
string strIDs = Request.QueryString["ids"];
if(strIDs != null)
{
    string[] ids = strIDs.Split(new[]{','}, StringSplitOptions.RemoveEmptyEntries);
    var no6 = ids.Where(id => id != "6");
    string newUrl = string.Format("Default.aspx?ids={0}", string.Join(",", no6));
    Response.Redirect(newUrl);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 c# 从 asp.net 中的查询字符串中删除项目? - How can I remove item from querystring in asp.net using c#? 如何使用 Linq 从 C# ASP.NET MVC 4 中的 IQueryable 中找到一个值? - How to find one value from an IQueryable in C# ASP.NET MVC 4 using Linq? 如何在C#的FOR循环中使用ASP.NET的标签ID? - How can I use ASP.NET's Label IDs in a FOR loop in C#? 使用ASP.NET(C#)在不使用QueryString的情况下将变量从页面传递到页面 - Passing Variable from page to page using ASP.NET (C#) without using QueryString C#ASP.NET QueryString解析器 - C# ASP.NET QueryString parser 如何使用asp.net和c#在mongodb中的同一id上一一动态地更新列值 - How to dynamic colums value update one by one on same id in mongodb using asp.net with c# 如何使用C#在ASP.NET中一一获取列表框中的项目 - how to get the items in listbox one by one in asp.net using c# 如何在C#中以一个Gridview的一个数据集显示两个相关的数据表? - How to show two related Datatables from one dataset in one Gridview in ASP.NET, C#? 如何使用C#给出指向标签的链接并将查询字符串传递给asp.net中的另一个页面 - how to give link to the label and pass querystring to another page in asp.net using c# ASP.NET C#-使用数据集读取一行? - ASP.NET C# - using dataset to read one row?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM