<table style="width: 100%">
<tr>
<td style="width: 100%; font-size: 9pt;">主题:<asp:DropDownList ID="ddl_VoteCode" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_VoteCode_SelectedIndexChanged" Width="190px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="font-size: 9pt; width: 100%; text-align: center;" valign="top"><div style="OVERFLOW: auto; WIDTH: 224px; HEIGHT: 193px">
<asp:GridView ID="gv_vote" runat="server" AutoGenerateColumns="False" Width="220px" OnRowDataBound="gv_vote_RowDataBound" DataKeyNames="VoteCode,IsSignSelect" Height="193px">
<Columns>
<asp:TemplateField HeaderText="此主题的投票内容">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"VoteName") %><asp:Panel runat="server" ID="ItemPanel" style="border: 1px solid #C0C0C0"></asp:Panel>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
</asp:TemplateField>
</Columns>
</asp:GridView></div>
<asp:ImageButton ID="Img_click" runat="server" ImageUrl="~/images/toupiao.jpg" border="0" OnClick="Img_click_Click" /></td>
</tr>
</table>
#region 得到当前的投票主题
private void BindSubjectData()
{
if (this.ddl_VoteCode.SelectedValue.ToString() != null)
{
DataTable BaseDt = VoteBaseDataDAL.GetListVoteName(this.ddl_VoteCode.SelectedValue.ToString());
if (BaseDt.Rows.Count==0)
{
this.Img_click.Visible = false;
}
else
{
gv_vote.DataSource = VoteBaseDataDAL.GetListVoteName(this.ddl_VoteCode.SelectedValue.ToString());
gv_vote.DataBind();
}
}
}
#endregion
#region 得到当前主题下的项目
protected void gv_vote_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string VoteCode = this.gv_vote.DataKeys[e.Row.RowIndex].Values[0].ToString();
string IsSignSelect = this.gv_vote.DataKeys[e.Row.RowIndex].Values[1].ToString();
Panel panel = (Panel)e.Row.FindControl("ItemPanel");
if (panel != null)
{
if (VoteCode.Length == 4)
{
if (IsSignSelect == "0")
{
RadioButtonList radiolist = new RadioButtonList();
radiolist.ID = "radiolist"; ///或者radiolist.ID = "radio";
BindItemDataByRadio(radiolist, gv_vote.DataKeys[e.Row.RowIndex].Values[0].ToString());
panel.Controls.Add(radiolist);
if (radiolist.Items.Count < 1)
{
panel.Controls.Add(new LiteralControl("<font color='red'>没有投票内容</font>"));
}
}
else if (IsSignSelect == "1")
{
CheckBoxList checklist = new CheckBoxList();
checklist.ID = "checklist";
BindItemDataByCkeck(checklist, gv_vote.DataKeys[e.Row.RowIndex].Values[0].ToString());
panel.Controls.Add(checklist);
if (checklist.Items.Count < 1)
{
panel.Controls.Add(new LiteralControl("<font color='red'>没有投票内容</font>"));
}
}
}
}
}
}
#endregion
#region 得到当前每个项下的内容(单选)
private void BindItemDataByRadio(RadioButtonList radiolist, string ParentCode)
{
radiolist.DataSource = VoteBaseDataDAL.GetListVoteName(ParentCode);
radiolist.DataTextField = "VoteName";
radiolist.DataValueField = "VoteCode";
radiolist.DataBind();
}
#endregion
#region 得到当前项下的内容(多选)
private void BindItemDataByCkeck(CheckBoxList checklist, string ParentCode)
{
checklist.DataSource = VoteBaseDataDAL.GetListVoteName(ParentCode);
checklist.DataTextField = "VoteName";
checklist.DataValueField = "VoteCode";
checklist.DataBind();
}
#endregion
<asp:GridView ID="gv_vote" runat="server" AutoGenerateColumns="False" Width="220px" OnRowDataBound="gv_vote_RowDataBound" DataKeyNames="VoteCode,IsSignSelect" Height="193px">
主键
DataKeyNames="VoteCode,IsSignSelect"