本文介绍了错误:对象引用未设置为字符串b处对象的实例。我需要在我的转发器中将radiobutton选择的值从mock.aspx传递到mock1.aspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误:对象引用未设置为字符串b处对象的实例。我需要在我的转发器中将radiobutton选择的值从mock.aspx传递到mock1.aspx
mock.aspx
___________
Error:object reference is not set to instance of an object at string b. i need to pass radiobutton selected value in my repeater from mock.aspx to mock1.aspx
mock.aspx
___________
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage1.master" AutoEventWireup="true" CodeFile="mock.aspx.cs" Inherits="mock" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<asp:Repeater ID="RepDetails" runat="server">
<HeaderTemplate>
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#df5015; color:White">
<td colspan="2">
<b>Questions:</b>
</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr style="background-color:#EBEFF0">
<td>
<table style="background-color:#EBEFF0;border-removed1px dotted #df5015; width:500px">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("qno") %>' Font-Bold="true"/>
<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("question") %>' Font-Bold="true"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
<tr>
<td>
<table style="background-color:#EBEFF0;border-removed1px dotted #df5015;border-removed1px solid #df5015; width:500px">
<tr>
<td>
<asp:RadioButton ID="RadioButton1" groupname="radio" Text='<%#Eval("option1") %>' EnableViewState="false" runat="server"/><br />
<asp:RadioButton ID="RadioButton2" groupname="radio" Text='<%#Eval("option2") %>' EnableViewState="false" runat="server"/><br />
<asp:RadioButton ID="RadioButton3" groupname="radio" Text='<%#Eval("option3") %>' EnableViewState="false" runat="server"/><br />
<asp:RadioButton ID="RadioButton4" groupname="radio" Text='<%#Eval("option4") %>' EnableViewState="false" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate></table>
</div>
<div><asp:Button id="btnnext" runat="server" Text="Next" OnClick="btnnext_Click"/><asp:Label ID="lblvalue" runat="server"></div>
mock.aspx.cs
________________
mock.aspx.cs
________________
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeaterData();
}
}
protected void BindRepeaterData()
{
SqlConnection con=new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select qno,question,option1,option2,option3,option4 from questionstable where qno BETWEEN 3 AND 6", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
da.Fill(ds);
RepDetails.DataSource = ds;
RepDetails.DataBind();
con.Close();
}
protected void btnnext_Click(object sender, EventArgs e)
{
foreach(RepeaterItem item in RepDetails.Items)
{
RadioButton box = (RadioButton)item.FindControl("radio");
string b = box.Text;
lblvalue.Text=b;
}
Response.Redirect("mock1.aspx?value="+lblvalue.Text);
}
mock1。 aspx.cs
_______________
mock1.aspx.cs
_______________
void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request.QueryString["value"].ToString();
}
推荐答案
这篇关于错误:对象引用未设置为字符串b处对象的实例。我需要在我的转发器中将radiobutton选择的值从mock.aspx传递到mock1.aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!