web 页面传多个参数问题

zye2004 2008-09-25 11:39:11
从一个页面传多个参数CG_CGDMXI.aspx?cgdhao={0}&gyshmcheng={1}&gyshbhao={2}&mid=34,其中出现问题如下:
cgdhao=DD200809010
gyshmcheng=徐水长虹橡塑有限公�?gyshbhao=GYSH0010
mid=34
本来供应商名称为:徐水长虹橡塑有限公司,供应商编号为: GYSH0010,但传过来的参数却是:gyshmcheng=徐水长虹橡塑有限公�?gyshbhao=GYSH0010,造成传过来的供应商编号为空。
并不是所有的都出现类似情况,有的传过来参数就正确,从网上查了一下解决办法:在web config 文件中加入代码:<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" /> ,这个问题确实解决了,但是我的界面-(如登陆界面,图标的位置有点乱),请问 如果不采用在web config中加代码,还有没有别的解决办法?谢谢!
...全文
183 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zye2004 2008-09-28
  • 打赏
  • 举报
回复
谢谢大家的解答,问题已经解决。解决方法如下:不传供应商名称(中文参数),传供应商编号,在接收端再由供应商编号去获得供应商名称。
violinacl 2008-09-28
  • 打赏
  • 举报
回复
留名
bonnibell 2008-09-26
  • 打赏
  • 举报
回复
大概整理了一下
以前大都动态生成模板列,动态生成模板列中的控件,
对在前台添加 还不太熟练,不对的请大家指正:

前台

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="名称">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="详情">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Show") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


后台

Dictionary<string, string> data = new Dictionary<string, string>();

data.Add("D0001", "徐水长虹橡塑有限公司1");
data.Add("D0002", "徐水长虹橡塑有限公司2");
data.Add("D0003", "徐水长虹橡塑有限公司3");
data.Add("D0004", "徐水长虹橡塑有限公司4");


DataTable Dt = new DataTable();
DataRow dr;
int id = 1;
Dt.Columns.Add("Num", typeof(string));
Dt.Columns.Add("Code", typeof(string));
Dt.Columns.Add("Name", typeof(string));
Dt.Columns.Add("Show", typeof(string));

foreach (string skey in data.Keys)
{

dr = Dt.NewRow();
dr[0] = id.ToString();
dr[1] = skey;
dr[2] = data[skey];
dr[3] = "<a href='CG_CGDMXI.aspx?cgdhao=" + Server.UrlEncode(skey) + "&gyshmcheng=" + Server.UrlEncode(data[skey]) + ">详情</a>";
Dt.Rows.Add(dr);
id++;
}


this.GridView1.DataSource = Dt;
this.GridView1.DataBind();


zye2004 2008-09-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 bonnibell 的回复:]
那就麻烦一点,在GridView的绑定事件里重新生成一次 HyperLinkField 的value
[/Quote]
麻烦你能说详细点吗?我还是不太懂该怎么做。
xbugirl 2008-09-25
  • 打赏
  • 举报
回复
难道不能把参数按照一定的规则整合成一个string然后传过去
diffmaker 2008-09-25
  • 打赏
  • 举报
回复

public static string GetParameterRaw(string paraname, string rawurl)
{
string paravalue = string.Empty;
string reg = "[&?]" + paraname + "=([^&]*)";
MatchCollection matches = Regex.Matches(rawurl, reg, RegexOptions.IgnoreCase);
if (matches.Count > 0)
{
paravalue = matches[0].Groups[1].Value;
}
paravalue = paravalue.Trim();
return paravalue;
}


如果是编码的问题,可以先将Request.RawUrl变一下编码,再提取
diffmaker 2008-09-25
  • 打赏
  • 举报
回复
试试在Request.RawUrl中提取参数呢?
zye2004 2008-09-25
  • 打赏
  • 举报
回复
难道除了修改webconfig文件就没有别的更好的解决方法了吗?
wanghousheng 2008-09-25
  • 打赏
  • 举报
回复
界面乱,和web.config没有关系的,还是想办法整一下界面吧,呵呵
bonnibell 2008-09-25
  • 打赏
  • 举报
回复
那就麻烦一点,在GridView的绑定事件里重新生成一次 HyperLinkField 的value
zye2004 2008-09-25
  • 打赏
  • 举报
回复
<asp:HyperLinkField DataNavigateUrlFields="CGDHAO,GYSHMCHENG,GYSHBHAO" DataNavigateUrlFormatString="CG_CGDMXI.aspx?cgdhao={0}&gyshmcheng={1}&gyshbhao={2}&mid=34"
DataTextField="CGDHAO" DataTextFormatString="采购明细" HeaderText="采购明细" Target="RightBottomFrame" />

我这是超链接,cgdhao,gyshmcheng,gyshbhao 这些都是字段,不能定义成具体某个值。
bonnibell 2008-09-25
  • 打赏
  • 举报
回复
string cgdhao = "DD200809010";
string gyshmcheng = "徐水长虹橡塑有限公";
string gyshbhao = "GYSH0010";
string strUrl = string.Format("CG_CGDMXI.aspx?cgdhao={0}&gyshmcheng={1}&gyshbhao={2}&mid=34", Server.UrlEncode(cgdhao), Server.UrlEncode(gyshmcheng), Server.UrlEncode(gyshbhao));
zye2004 2008-09-25
  • 打赏
  • 举报
回复
bonnibell,用Server.UrlEncode 具体怎么用阿?比如CG_CGDMXI.aspx?cgdhao={0}&gyshmcheng={1}&gyshbhao={2}&mid=34,应该怎么写啊?
bonnibell 2008-09-25
  • 打赏
  • 举报
回复
Server.UrlEncode

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧