Editing all the rows in a GridView (Bulk edit)

clock October 4, 2007 10:26 by author Nazar Rizvi

I was trying to find a solution which did bulk updating for all the rows in a gridview, as the gridview provided by VS2005 had its usability issue (at least that's what I thought). After doing some googling I found a set of different grid views available at codeplex called 'ASP.NET Real World Controls'.

Its got a BulkEditGridView, FrozenGridView, GroupingGridView, InlineInsertGridView and TwoHeadedGridView. You can get a hold of the .dll file from http://www.codeplex.com/ASPNetRealWorldContr.
Here is an example of bulk edit grid view.

<cc1:BulkEditGridView ID="BulkEditGridView1" runat="server" AutoGenerateColumns="False"            

DataKeyNames="CategoryID" DataSourceID="AccessDataSource1" EnableInsert="False"            

InsertRowCount="1" SaveButtonID="Button1" AllowPaging="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" Width="502px"><Columns>

<asp:BoundField ReadOnly="True" DataField="CategoryID" InsertVisible="False" SortExpression="CategoryID" HeaderText="CategoryID"></asp:BoundField>

<asp:BoundField DataField="CategoryName" SortExpression="CategoryName" HeaderText="CategoryName"></asp:BoundField>

<asp:BoundField DataField="Description" SortExpression="Description" HeaderText="Description"></asp:BoundField>

</Columns>            

<FooterStyle BackColor="Tan" />            

<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />            

<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />            

<HeaderStyle BackColor="Tan" Font-Bold="True" />            

<AlternatingRowStyle BackColor="PaleGoldenrod" /> </cc1:BulkEditGridView>        

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Nwind.mdb"            

DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = ?" InsertCommand="INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES (?, ?, ?)"             SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"            

UpdateCommand="UPDATE [Categories] SET [CategoryName] = ?, [Description] = ? WHERE [CategoryID] = ?">             <DeleteParameters>                 <asp:Parameter Name="CategoryID" Type="Int32" />             </DeleteParameters>            

<UpdateParameters>                 <asp:Parameter Name="CategoryName" Type="String" />                

<asp:Parameter Name="Description" Type="String" />                 <asp:Parameter Name="CategoryID" Type="Int32" />            

 </UpdateParameters>             <InsertParameters>                 <asp:Parameter Name="CategoryID" Type="Int32" />      

           <asp:Parameter Name="CategoryName" Type="String" />                 <asp:Parameter Name="Description" Type="String" />             </InsertParameters>         </asp:AccessDataSource>         <asp:Button ID="Button1" runat="server" Text="Update" Width="200px" />

 


You just need to make sure that you changed the SaveButtonID property to the button's ID.


 

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Date Validation in ASP.NET

clock October 4, 2007 08:24 by author Nazar Rizvi

I have seen many people who had issues with date validation (validating a textbox for a date field). Usually they end up writing regular expressions which work fine but there is a much easier way to to it using Visual Studio 2005. (And I am not talking about using the AJAX Control Toolkit)

You can use a 'Compare Validator' and in its behavior attributes provide the textbox name for "ControlToValidate", set the "Operator" to DataTypeCheck and the "Type" to Date. And this should work fine.

Below is the image for this control.

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Dictionary words populated to your TextBox (similar to Google labs)

clock October 3, 2007 21:25 by author Nazar Rizvi

1. Now for this one I got hold of one of the dictionary files from a dictionary attack and converted into an access DB.

2. Then went ahead and built an AJAX enabled website using VS 2005.

3. Added up a TextBox and an AutoCompleteExtender.

4. Add an AutoComplete page method from the tasks.

Code of the .aspx page:

<form id="form1" runat="server">        
<asp:ScriptManager ID="ScriptManager1" runat="server" />        
<div>            
Automatically generating words for a textbox using asp.net ajax:
<br />            
<br />            
<asp:TextBox ID="TextBox1" runat="server" Width="372px"></asp:TextBox><br />            
<br />            
<cc1:AutoCompleteExtender TargetControlID="TextBox1" MinimumPrefixLength="1" ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompletionList"                
UseContextKey="True">            
</cc1:AutoCompleteExtender>        
</div>    
</form>


4. Added up the following code in the .cs file where in I am doing a simple query and calling up the web service method.

public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
if (count == 0){count = 10;}string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\Users\\abbas\\Desktop\\site1\\App_Data\\db01.mdb'";
OleDbConnection conn = new OleDbConnection(connString);string sql = "SELECT [Desc]FROM Table1 WHERE Desc LIKE (@value + '%')";
OleDbCommand myCmd = new OleDbCommand(sql, conn);
myCmd.Parameters.Add(new OleDbParameter("@value", System.Data.SqlDbType.Text));
conn.Open();myCmd.Parameters["@value"].Value = prefixText.ToString();
OleDbDataReader reader = myCmd.ExecuteReader();int i = 0;
ArrayList arrNames = new ArrayList();while (reader.Read() && i < 20){arrNames.Add(reader[0].ToString());i++;
}
conn.Close();
return (string[])(arrNames.ToArray(connString.GetType()));}


And here it goes. I just kept the number of results to 20.





(for the DB. Download a dictionary wordlist. Create a Db with one table and import the data. There you go. If you need the DB or the wordlist just email me)

 

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Image Display: ASP.net AJAX

clock October 3, 2007 18:22 by author Nazar Rizvi

If you have an image search built in your application and want to have a display similar to that of the live image search you can follow this procedure.

Use a DataList to display your search results and make use of the HoverMenuExtender (one of the new controls from the AJAXcontrolToolkit. You can Change the CSS style to obtain your desired look.

Here is the sample code.


The result of this code:

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Search

About me

I am Nazar Rizvi and I work as a .NET Developer on projects at Geneca. If you need more info you can visit narizvi.com.

Calendar

<<  September 2010  >>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Archive

Tags

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in