I want to do a survey. In my project , I have a problem. That is;
RadioButtonList AND ListItem in gridview dosent work in GridView1_PageIndexChanging sub; when I click a
"next button" on the bottom of the page, it is not retaining the
users selection. It either retains -1 (no selection), or whatever I
set it to during the GridView1_PageIndexChanging event.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Height="118px"
Width="563px" style="margin-top: 0px"
onpageindexchanging="GridView1_PageIndexChanging"
onrowdatabound="GridView1_RowDataBound1"
AllowPaging="True" onpageindexchanged="GridView1_PageIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="İlk" PreviousPageText="Geri" NextPageText="İleri" LastPageText="Son" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<ItemStyle Width="5px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Soru" SortExpression="Soru">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Soru") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("Soru") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Justify" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="column1" SortExpression="column1" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("column1") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("column1") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Justify" />
<ItemStyle Width="8px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="rblChoices" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
<asp:ListItem Value="4"></asp:ListItem>
<asp:ListItem Value="5"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
<ItemStyle Width="130px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Anket_ID" SortExpression="Anket_ID" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Anket_ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label16" runat="server" Text='<%# Bind("Anket_ID") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Justify" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="User_ID" SortExpression="User_ID" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("User_ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label17" runat="server" Text='<%# Bind("User_ID") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Justify" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="UygSoru_ID" SortExpression="UygSoru_ID" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("UygSoru_ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("UygSoru_ID") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Justify" />
<ItemStyle Width="200px" />
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
and in c#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButtonList c = (RadioButtonList)GridView1.Rows[i].Cells[3].FindControl("rblChoices");
Label anketid = (Label)GridView1.Rows[i].Cells[4].FindControl("Label16");
Label userid = (Label)GridView1.Rows[i].Cells[5].FindControl("Label17");
Label soruid = (Label)GridView1.Rows[i].Cells[6].FindControl("Label18");
if (c.SelectedIndex > -1)
{
Label20.Text = "You selected: " + c.SelectedItem.Text;
}
}
}
then ; when I clıck "next" or "back" button ; ı dont see selectedvalues;
in fact
Label20.Text = "You selected: " + c.SelectedItem.Text;
that must work but it doesnt work??
What is the problem;
Thanksss