I have buttons (a href links) that are styled with CSS to look/act like a button. How do I hook these existing buttons up to edit a single row or delete the row. They appear in the last cell dgvStaff.Columns[7] of each row.
So when I click the edit button: <a href='#' class='sepV_a' title='Delete' onclick='alert(""Delete staff"")'><i class='splashy-calendar_day_remove'></i></a>
It would allow me to edit the row. Do I need to change the html in any way or can it work with the html I provided above?
Also for the same, how would I make the delete button delete the row?
I am using Infragistics v12.1 WebDataGrid
I'm glad to hear that.
Please feel free to contact me if you have any other questions.
Alright I was able to get that all to work, thank you very much!
Hi OmegaPrime,
I would suggest you to try binding the grid only first time the page loads. Then set EnableViewState and EnableDataViewState to true. Also, make sure you have enabled the row deleting behavior of the grid. I am attaching a sample, demonstrating your scenario.
If you have any questions regarding the matter, please let me know.
Any idea what I am missing here?
I added the DataKeyFields property:
dgvStaff.DataSource = Staff; dgvStaff.DataKeyFields = "stfGID";
It is giving me a null exception error now when I click Delete and doing the same as before when I click Edit. All the code to load the WebDataGrid should be below along with the HTML of the Grid itself. Anything I am missing here?
private DataTable Staff { get { object obj = this.ViewState["_gds"]; if ((((obj) != null))) { return (DataTable)obj; } else { DataTable table = objDataFunctions.GetCustStaff(Session["LoginID"].ToString(), ConfigurationManager.AppSettings.Get("Connection").ToString()); DataColumn[] Col = { table.Columns["stfGID"] }; table.PrimaryKey = Col; return table; } } }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (Session.IsNewSession == true) { Response.Write("<script language='javascript'>window.open('" + ConfigurationManager.AppSettings.Get("LoginAddress").ToString() + "?TimeOut=TRUE', '_parent')</script>"); }
}
dgvStaff.DataSource = Staff; dgvStaff.DataKeyFields = "stfGID"; }
<ig:WebDataGrid ID="dgvStaff" Width="100%" runat="server" AutoGenerateColumns="False" ClientIDMode="Static"> <Columns> <ig:BoundDataField DataFieldName="stfGID" Hidden="True" Key="stfGID"> <Header Text="stfGID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="stfFK_cstGID" Hidden="True" Key="stfFK_cstGID"> <Header Text="stfFK_cstGID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Position" Key="Position"> <Header Text="Position" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="First Name" Key="First Name"> <Header Text="First" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Last Name" Key="Last Name"> <Header Text="Last" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Email" Key="E-Mail"> <Header Text="Email" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Appts" Hidden="True" Key="Appts"> <Header Text="Appointment" /> </ig:BoundDataField> <ig:TemplateDataField Key="TemplateField_0"> <ItemTemplate> <asp:LinkButton ID="Delete" CssClass="sepV_a" OnClientClick="return deleteRow()" ToolTip="Delete" runat="server"><i class='splashy-calendar_day_remove'></i></asp:LinkButton> <asp:LinkButton ID="Edit" CssClass="sepV_a" OnClientClick="return editRow()" ToolTip="Edit" runat="server"><i class='splashy-calendar_month_edit'></i></asp:LinkButton> </ItemTemplate> <Header Text="Delete / Edit" /> </ig:TemplateDataField> </Columns> <Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Activation> </ig:Activation> </Behaviors> </ig:WebDataGrid>