如果Request.QueryString ['EQCN']不存在,我想将textbox.text设置为某个值。如果确实存在,我想将其设置为Requestion.QueryString ['EQCN']的值。
似乎如果该值不存在,则默认值为“”。
有什么想法吗?
非常感谢!!!
答案 0 :(得分:4)
如果参数不在查询字符串中,则QueryString索引器将返回null
引用,因此您可以使用??
运算符作为默认值:
textbox.text = Request.QueryString['EQCN'] ?? "default text";
答案 1 :(得分:3)
textbox.text = string.IsNullOrEmpty(Request.QueryString["EQCN"]) ? "my value" : Request.QueryString["EQCN"];