過去2日間、次の問題が発生しています。
ユーザーがドロップダウンリストから投票を選択する投票を作成したいと思います。選択すると、選択したポーリングはIDに基づいてデータベースからデータをフェッチし、ラジオボタンリストに日付1、日付2、日付3の3つのオプションを入力します。
作成された投票のID、有効期限データ、日付1、日付2、日付3を格納するデータベーステーブルがあります。
作成された投票のドロップダウンリストを生成することはできますが、放射ボタンリストにさまざまな日付オプションを入力するように選択されたときに、選択された投票を応答させることができません。以下は、私が書いたコードのスニペットです。
protected void Page_Load(object sender, EventArgs e)
{
fillPollOptions();
if(pollDropDownList.SelectedIndex > 0){
MultiView1.Visible = true;
btnListPollOptions.Visible = true;
pollDateCreated();
}
}
public void fillPollOptions()
{
pollDropDownList.Items.Clear();
string selectSQL = "SELECT id, dateExpired FROM tblPolls";
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
ListItem newItem = new ListItem();
newItem.Text = reader["id"].ToString();
newItem.Value = reader["dateExpired"].ToString();
pollDropDownList.Items.Add(newItem);
}
reader.Close();
}
catch (Exception err)
{
lblListError.Text = "Error reading list of names. ";
lblListError.Text += err.Message;
}
finally
{
con.Close();
}
}
public void pollDateCreated()
{
string selectSQL = "SELECT dateExpired, dateCreated FROM tblPolls";
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
lblQuestionDateCreated.Text = reader["dateCreated"].ToString();
lblQuestionDateExpires.Text = reader["dateExpired"].ToString();
reader.Close();
}
catch (Exception err)
{
lblListError.Text = "Error reading list of names. ";
lblListError.Text += err.Message;
}
finally
{
con.Close();
}
}
protected void btnPollList()
{
string selectSQL;
selectSQL = "SELECT firstDate,secondDate,thirdDate FROM tblPolls ";
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
btnListPollOptions.DataSource = reader;
btnListPollOptions.DataBind();
reader.Close();
}
catch(Exception ex){
lblMessage.Text = "Error displaying poll";
}
}
フロントエンドにデータソースバインディングが必要かどうかはわかりません。私の.aspコードは次のとおりです。
<asp:DropDownList ID="pollDropDownList" runat="server" Height="16px"
Width="132px" >
</asp:DropDownList>
<asp:RadioButtonList ID="btnListPollOptions" runat="server"
DataTextField="firstDate, secondDate, thirdDate" DataValueField="id">
<asp:ListItem>Not Available</asp:ListItem>
</asp:RadioButtonList>
何か助けていただければ幸いです!!
ありがとうございました!