问题描述
我想做一个调查。在我的项目中,我有一个问题。那就是;
GridView中的RadioButtonList和ListItem在GridView1_PageIndexChanging子中工作;当我点击页面底部的
下一步按钮时,它不会保留
用户选择。它要么保留-1(没有选择),要么在GridView1_PageIndexChanging事件期间将它设置为它。
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#
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 ettiket = (Label)GridView1.Rows[i].Cells[2].FindControl("Label19");
// Label ettiket = (Label)GridView1.Rows[i].Cells[2].FindControl("Label19");
switch (ettiket.Text)
{
case "1": c.SelectedIndex = 0; break;
case "2": c.SelectedIndex = 1; break;
case "3": c.SelectedIndex = 2; break;
case "4": c.SelectedIndex = 3;break;
case "5": c.SelectedIndex = 4; break;
}
*/
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;
// BusinessLayer.UserAnketKaydet(Convert.ToInt16(anketid.Text), Convert.ToInt16(soruid.Text), 1, Convert.ToInt16(userid.Text));
}
}
}
then ; when I clıck \"next\" or \"back\" button ; ı dont see selectedvalues;
in fact
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
that must work but it doesnt work??
What is the problem;
Thanksss
推荐答案
<asp:radiobuttonlist id="rblChoices" runat="server" repeatdirection="Horizontal" onselectedindexchanged="rblCategories_SelectedIndexChanged" autopostback="True" xmlns:asp="#unknown">
</asp:radiobuttonlist>
then
then
protected void rblCategories_SelectedIndexChanged(object sender, EventArgs e)
{
var listControl = (ListControl)sender;
var row = (GridViewRow)listControl.NamingContainer;
var item = listControl.SelectedItem;
Label anketid = (Label)row.FindControl("Label16");
Label userid = (Label)row.FindControl("Label17");
Label soruid = (Label)row.FindControl("Label18");
try
{ label20.Text= item.Text /Radio Button Selected Value
// BusinessLayer.UserAnketKaydet(Convert.ToInt16(anketid.Text), Convert.ToInt16(soruid.Text), Convert.ToInt16(item.Text), Convert.ToInt16(userid.Text));
}
catch
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.SelectedIndex = -1;
BindGrid(); // Call bind here
}
这篇关于RadioButtonList.SelectedIndex在GridView1_PageIndexChanging sub中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!