更改表gridview的选择错了行 [英] change table gridview select wrong row
问题描述
我的页面加载从数据库中加载的GridView
和我有文本框和搜索按钮可以改变gridview的。但问题是gridview_selectindexchanging选择错了行。
i have page load to load gridview from database and i have textbox and search button can change the gridview. but that problem is gridview_selectindexchanging select wrong row.
protected void GridView1_SelectedIndexChanging1(object sender, GridViewSelectEventArgs e)
{
lbl_1.Visible = true;
lbl_2.Visible = true;
lbl_3.Visible = true;
lbl_4.Visible = true;
lbl_5.Visible = true;
lbl_6.Visible = true;
lbl_7.Visible = true;
btn_submit.Visible = true;
lbl_nama.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
lbl_alamat.Text = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
lbl_hp.Text = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
lbl_kode.Text = GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
lbl_peminjaman.Text = GridView1.Rows[e.NewSelectedIndex].Cells[5].Text;
lbl_pengembalian.Text = GridView1.Rows[e.NewSelectedIndex].Cells[6].Text;
DateTime kembali = DateTime.ParseExact(lbl_pengembalian.Text,"dd-MM-yyyy",CultureInfo.InvariantCulture);
if (DateTime.Now > kembali)
{
lbl_denda.Text = "Rp.20000,-";
}
else
{
lbl_denda.Text = "Rp.0,-";
}
}
和
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" style="text-align: left" AutoGenerateSelectButton="true" OnSelectedIndexChanging="GridView1_SelectedIndexChanging1">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
如何解决这个问题呢?
how to fix this problem?
推荐答案
我想你可能会寻找 EnablePersistedSelection
属性。
I think you may be looking for the EnablePersistedSelection
property.
获取或设置一个值,该值指示行的选择是
基于索引或数据键值
Gets or sets a value that indicates whether the selection of a row is based on index or on data-key values
如果此属性为false并选择一排,同样排
当显示一个新的页面,即使新的页面选择
在它的不同的数据。如果此属性,当你设置为true
显示中有不同的数据的页面,没有行被选中。如果
你然后返回到其上选择的行的页面,该行是
仍处于选中状态。
If this property is false and a row is selected, the same row is selected when a new page is displayed even though the new page has different data in it. If you set this property to true, when you display a page that has different data in it, no row is selected. If you then return to the page on which a row was selected, that row is still selected.
这篇关于更改表gridview的选择错了行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!