Frågan#1 Hej!
Jag har en gridview där jag skulle vilja ha möjligheten att ta bort en rad utan att binda om gridviewen. Är det möjligt?
Tanken är att detta skulle ske i gridviewens rowcommand event.
DDinoMedlem sedan sep. 20011 914 inlägg <asp:gridview id="GridView1" runat="server" allowpaging="True" autogeneratecolumns="False" onrowcreated="GridView1_RowCreated" onrowcommand="GridView1_RowCommand">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:button id="bt1" text="Remove" commandname="remove" runat="server" />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
List<int> col = ViewState["grr"] == null ? new List<int>() : ViewState["grr"] as List<int>;
int index = (GridView1.PageIndex * GridView1.PageSize) + e.Row.RowIndex;
((Button)e.Row.FindControl("bt1")).CommandArgument = index.ToString();
if (col.Contains(index))
e.Row.Visible = false;
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "remove")
{
Button bt = e.CommandSource as Button;
int index1 = int.Parse(bt.CommandArgument);
int index2 = index1 - (GridView1.PageIndex * GridView1.PageSize);
GridView1.Rows[index2].Visible = false;
List<int> col = ViewState["grr"] == null ? new List<int>() : ViewState["grr"] as List<int>;
if (!col.Contains(index1))
col.Add(index1);
ViewState["grr"] = col;
}
}
Jag beundrar din kunskap. Du är ett äkta proffs.
Spännande att du sätter ditt eget inlägg som lösningen.
Haha, till skillnad från Dino är jag inte ofelbar. Nu är det fixat.