-
Need to solve the paging issue and triggering of dynamic buttons. without using OnInit() paging is working fine but the dynamic buttons will not fire
//Pageload if (!IsPostBack) { Bind(); }
protected override void OnInit(EventArgs e) { Bind(); }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ //some code foreach (string item in split_old_transaction_id) { buttonArray[i] = new LinkButton(); buttonArray[i].ID = item; buttonArray[i].Text = item; buttonArray[i].CommandName = "Select_related_co"; buttonArray[i].CommandArgument = item; buttonArray[i].CausesValidation = false; e.Row.Cells[7].Controls.Add(buttonArray[i]); i++; } }
protected void OnCheckedChanged(object sender, EventArgs e) { bool isUpdateVisible = false; CheckBox chk = (sender as CheckBox); if (chk.ID == "check_all") { foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { row.Cells[15].Controls.OfType().FirstOrDefault().Checked = chk.Checked;
} } } foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { bool isChecked = row.Cells[15].Controls.OfType<CheckBox>().FirstOrDefault().Checked; for (int i = 1; i < row.Cells.Count; i++) { row.Cells[14].Controls.OfType<Label>().FirstOrDefault().Visible = !isChecked; row.Cells[13].Controls.OfType<Label>().FirstOrDefault().Visible = !isChecked; if (row.Cells[i].Controls.OfType<TextBox>().ToList().Count > 0) { row.Cells[i].Controls.OfType<TextBox>().FirstOrDefault().Visible = isChecked; } if (isChecked && !isUpdateVisible) { isUpdateVisible = true; } } } }
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) {
GridView1.PageIndex = e.NewPageIndex; BindTransactionsPerCustomer();
}
protected void ddl_PageSize_SelectedIndexChanged(object sender, EventArgs e) { if (ddl_PageSize.SelectedValue != "--") { GridView1.PageSize = Convert.ToInt32(ddl_PageSize.SelectedValue); BindTransactionsPerCustomer(); } }
ASPX CODE
</HeaderTemplate> <ItemTemplate> <asp:Label ID="Label22" runat="server" Text="EDIT"></asp:Label> <asp:CheckBox ID="CheckBox1" runat="server" CssClass="gridcheckbox" Checked="false" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" /> </ItemTemplate>
mardi 18 septembre 2018
Dynamic button array,Paging and select/unselect checkbox using c#
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire