C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Bulk Editing Of Gridview


Posted Date: 05 Dec 2007    Resource Type: Articles    Category: .NET Framework

Posted By: Tamilarasi Elumalai       Member Level: Bronze
Rating:     Points: 10



<H2>Introduction</H2>

Consider a gridview , which contains employee’s shift details of bpo. If the admin wants to change timings of some 25 numbers of employee means he have to select 25 records as one by one and edit the information. To avoid this we can design the all row of gridview in edit mode by single click.

<H2>To Make all the rows in edit mode</H2>

First change all the bound field of gridview in templatecolumn field.
Drag and Drop a text box in item template field for the column which wants to edit.
Now you can see one label and textbox fields in itemtemplate. If label box is in visible the gridview in read only mode and the textbox visible then gridview in edit mode.
To change the Visible properties of Textbox and Label box create one property which return true or false.

public bool _visible = false;
public bool IsVisible
{
get
{
return _visible;
}
set
{
_visible = value;
}

}

Now set the value for both textbox and lable visible property as

<ItemTemplate>
<asp:Label ID="Label4" runat="server" Visible='<%# !(bool) IsVisible %>'
Text='<%# Bind("max") %>'>
</asp:Label>
<asp:TextBox ID="TxtMax" Visible='<%#IsVisible %>' Text='<%#Bind("max") %>'
runat="server">
</asp:TextBox>
</ItemTemplate>

Now to make all the rows in edit mode write set IsVisible = true in Edit_Button Click Event.

protected void Edit_Button_Click(object sender, EventArgs e)
{
_Visible = true;
GridView1.DataBind();

}



<H2>To Update All Rows. </H2>

Write the following code in update Button click event.

protected void Update_Button_Click(object sender, EventArgs e)
{
for (int i=0;i< GridView1.Rows.Count;i++)
Gridview1.UpdateRow(i, true);
_Visible = false;
Gridview1.DataBind();

}

Now all the Rows will Update by each for loop. When UpdateRow() methed executes it will automatically calls the 'RowUpdate' event of Gridview. No need to create Update query for Update_allrows if you already specified in 'RowUpdate' Event


<H2>Summary</H2>

I hope this article help to programmer who all are search for bulk updating.

Enjoy programming...............





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Gridview  .  Editing  .  Bulk  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Generating Excel sheet using Excel XML
Previous Resource: Simple Steps to Work on a share point portal
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

masks masks masks

Contact Us    Privacy Policy    Terms Of Use