Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



ASP / ASP.NET ASP Tutorial , ASP.NET Basic , ASP Advanced , ASP Database , ASP.NET XML , beginner's guide,primer,training,learning,internet,database,development,Web building,Webmasterhowto,reference,examples,samples, ASP Servers , ASP.NET Codes , ASP Articles .

ASP / ASP.NET Thread, Editing in DataGrid and Default Paging - ASP.NET / Databases / in Web Development; Lesson Keywords: ASP.NET / Databases / Code / Datagrid This is an example of editing in DataGrid and Default Paging ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=92


Reply
LinkBack Thread Tools Display Modes
Editing in DataGrid and Default Paging - ASP.NET / Databases /
 
 
Junior Member

Reply With Quote
 
Join Date: Sep 2007
Posts: 1
04-10-2007, 10:01 PM
 
Lesson Keywords: ASP.NET / Databases / Code / Datagrid

This is an example of editing in DataGrid and Default Paging



Html Design Code : -

PHP Code:
 <asp:DataGrid 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:DataGrid>

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.DataGridPageChangedEventArgs e)
        {
            
DataGrid1.CurrentPageIndex = e.NewPageIndex;
            
BindGrid();
 
 
 
 
Choose
SABRAWY's Avatar

Reply With Quote
 
Join Date: Aug 2007
Posts: 1,893
16-11-2007, 06:19 PM
 
thank you very much
 
 
 
Reply

ASP / ASP.NET Thread, Editing in DataGrid and Default Paging - ASP.NET / Databases / in Web Development; Lesson Keywords: ASP.NET / Databases / Code / Datagrid This is an example of editing in DataGrid and Default Paging ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=92


Bookmarks

Tags
aspnet, databases, datagrid, default, editing, paging

« - | What is ASP.NET ? »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Green Style Developer Styles for 3.6.x 0 27-10-2008 09:32 PM
Audacity - Music Editing Software Developer Software and Programs 0 27-10-2008 06:50 PM
Move threads with leave no redirect as default or Expired redirect as default Developer Mods for 3.6.x 0 23-09-2008 12:52 AM
Class - AJAX DataGrid SABRAWY Classes & Source Code 1 21-09-2008 01:03 AM
Template Editing - All the variables and coding bits you need to know! Developer Articles 0 10-09-2008 07:16 PM