|
| |||||||
![]() | Welcome to iWEBTOOL Talk, where you talk about
webmaster-related stuff.
1 Register
2 Browse the board
3 Discuss whatever may interest you! | |||||||||||||
![]() |
| | Thread Tools | Search this Thread | Display Modes |
| | #1 |
| Smurf Join Date: Sep 2007
Posts: 7
![]() | This is an example of editing in DataGrid and Default Paging http://www.hanusoftware.com Html Design Code : - <asp ataGrid id="DataGrid1" DataKeyField="id" runat="server" Height="224px" AutoGenerateColumns="False" PageSize="5" AllowPaging="True"><Columns> <asp:BoundColumn Visible="False" DataField="id" HeaderText="Category Id"></asp:BoundColumn> <asp:TemplateColumn HeaderText="Category"> <ItemTemplate> <asp:Label id=lblName text='<%# DataBinder.Eval(Container.DataItem,"name")%>' Runat="server"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox id=txtEdit Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"name")%>'> </asp:TextBox> </EditItemTemplate> </asp:TemplateColumn> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> </Columns> </asp ataGrid>Code (EditInDataGrid.aspx.cs) : private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!IsPostBack) { BindGrid(); } } private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex = e.Item.ItemIndex; BindGrid(); } private void BindGrid() { SqlDataAdapter da = new SqlDataAdapter("select id,name from category",con); DataSet objDS = new DataSet(); try { da.Fill(objDS,"Cat"); if(objDS.Tables[0].Rows.Count != 0) { DataGrid1.DataSource = objDS; DataGrid1.DataBind(); } else { DataGrid1.DataSource = null; DataGrid1.DataBind(); Response.Write("No record found."); } } catch(Exception ex) { throw ex; } } private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { try { string strCatName = ((TextBox)e.Item.FindControl("txtEdit")).Text; string strId = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); SqlCommand com = new SqlCommand("update category set name ='"+strCatName+"' where id = "+strId,con); con.Open(); com.ExecuteNonQuery(); DataGrid1.EditItemIndex = -1; BindGrid(); } catch(Exception ex) { throw ex; } } private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex = -1; BindGrid(); } private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; BindGrid();
__________________ http://www.hanusoftware.com |
| |
|
| |||||||
(Threads which have no activity for more than 30 days are automatically closed.) |
| Quick Reply | ||
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help editing something - im using myphpadmin | CircleOfLinks | PHP | 0 | 10-01-2007 06:00 AM |
| What shall I use for web graphics editing? | tanya004 | Tools & Software | 9 | 06-17-2006 02:53 AM |