Reputation: 93
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,-";
}
}
and
<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?
Upvotes: 0
Views: 186
Reputation:
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
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.
Upvotes: 1