C# 无法进行响应。重定向无法工作

C# 无法进行响应。重定向无法工作,c#,button,submit,response.redirect,C#,Button,Submit,Response.redirect,我有这个简单的代码,我想检查客户类型是否为商业客户。否则,将出现错误。如果是,它将被引导到另一页。我是不是遗漏了什么 protected void Button1_Click(object sender, EventArgs e) { if ("Customer Type" != "Commercial Customer") { lblerror.Text = "For commercial customers only";

我有这个简单的代码,我想检查客户类型是否为商业客户。否则,将出现错误。如果是,它将被引导到另一页。我是不是遗漏了什么

protected void Button1_Click(object sender, EventArgs e)
    {
        if ("Customer Type" != "Commercial Customer")
        {
            lblerror.Text = "For commercial customers only";
        }
        else
        {
            Response.Redirect("CreditRequestRegistration.aspx");
        }

    }
这是我的aspx代码:

<ItemTemplate>  
              <table id="tblcustomerprofile" border="1" cellpadding="1" cellspacing="0">
                   <tr>
                        <%--<td style="width:100px">
                            ID:
                        </td>
                        <td style="width:250px">
                            <strong><%# Eval("ID")%></strong>
                        </td>--%>
                   <tr>
                        <td class="style1" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Username:
                        </td>
                        <td class="style2" style ="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Username")%></strong>
                        </td>
                        <tr>
                        <td class="style3" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            FirstName:
                        </td>
                        <td class="style4" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Firstname")%></strong>
                        </td>
                        <tr>
                        <td class="style20" 
                                style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            LastName:
                        </td>
                        <td class="style21" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Lastname")%></strong>
                        </td>                            
                    <tr>
                        <td class="style9" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Email Address:
                        </td>
                        <td class="style10" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Email")%></strong>
                        </td>
                        <tr>
                        <td class="style11" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Password:
                        </td>
                        <td class="style12" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Password")%></strong>
                        </td>                                                        
                    </tr>
                    <tr>
                        <td class="style13" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Customer Type:
                        </td>
                        <td class="style14" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("CustomerType")%></strong>
                        </td>                                                        
                    </tr>                        
                    <tr>
                        <td class="style15" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Delivery Address:
                        </td>
                        <td class="style19" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("DeliveryAddress") %></strong>
                        </td>
                        <tr>
                        <td class="style15" style="border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Zip Code:
                        </td>
                        <td class="style19" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("Zip")%></strong>
                        </td>                                                                                  
                    </tr>
                        <tr>                            
                        <td class="style17" style=" border-style:ridge; border-width:thick; border-color:White;  background-color:#FF3300; font-size:small; color:White">
                            Contact Number:
                        </td>
                        <td class="style18" style="border-style:ridge; border-width:thin">
                            <strong><%# Eval("ContactNumber")%></strong>
                        </td>
                    </tr>
                </table>


                    <asp:LinkButton ID="EditButton" ForeColor="Blue"
                                    Text="Update Profile"
                                    CommandName="Edit"
                                    RunAt="server"/>
                      &nbsp;

            </ItemTemplate>

用户名:

名字:

姓氏:

电邮地址:

密码:

客户类型:

送货地址:

邮政编码:

联络电话:


您正在比较两个明显不相等的字符串。else部分将如何执行?如果它们在gridview中,我如何比较它们?Customertype是标题,Commercial Customer在数据字段中。您可以使用foreach循环formview控件,并比较“Customer type”列中的文本。您可以给我一个示例吗?我真的非常感谢@parthat这会给你一些想法: