Vous êtes sur la page 1sur 3

29/11/13

GridView CommandArgument, passing multiple values | C# Guide - C#, Asp.Net, MVC, LINQ, jQuery and SharePoint Resources
Ms Siguiente blog Crear un blog Acceder

C# Guide - C#, Asp.Net, MVC, LINQ, jQuery and SharePoint Resources

Home

Site Map

C#

Asp.Net

MVC

LINQ

ADO.Net

jQuery

SharePoint

Books

Tools / Utilities

Monday, May 21, 2012

GridView CommandArgument, passing multiple values


A Button or a link button in a GridView can pass a value to the RowCommand event in the code behind file using the CommandArgument property.

Subscribe Now Subscribe via email

< a s p : G r i d V i e w I D = " g r d E m p l o y e e " r u n a t = " s e r v e r " O n R o w C o m m a n d = "g r d E m p l o y e e _ R o w C o m m a n d " > < C o l u m n s > < a s p : T e m p l a t e F i e l dH e a d e r T e x t = " E m p l o y e eN a m e " > < I t e m T e m p l a t e > < a s p : L i n k B u t t o n I D = " l n k n a m e " r u n a t = " s e r v e r " T e x t = ' < % # E v a l ( " E M P L O Y E E _ N A M E " )% > ' C o m m a n d A r g u m e n t = ' < % # E v a l ( " E M P L O Y E E _ I D " )% > ' C o m m a n d N a m e = " l i n k B u t t o n " > a s p : L i n k B u t t o n > I t e m T e m p l a t e > a s p : T e m p l a t e F i e l d > C o l u m n s > a s p : G r i d V i e w > Here the column is a link button column and will display the employee name, on clicking the link button the RowCommand event of the GridView is fired, and we are passing the EMPLOYEE_ID value to the row command property. p r o t e c t e dv o i dg r d E m p l o y e e _ R o w C o m m a n d ( o b j e c ts ,G r i d V i e w C o m m a n d E v e n t A r g se ) { i n ti n t E m p I d=0 ; i f( e . C o m m a n d N a m e= =" l i n k B u t t o n " ) { i n t E m p I d=C o n v e r t . T o I n t 3 2 ( e . C o m m a n d A r g u m e n t ) ; } } This is fine for passing a single value to the code behind event, what if we need to pass more than one value to the code behind event, here is the code to acchieve the same. Here we are passing the Employee_ID and Manager_ID values to the code behind event. < a s p : G r i d V i e w I D = " g r d E m p l o y e e " r u n a t = " s e r v e r " O n R o w C o m m a n d = "g r d E m p l o y e e _ R o w C o m m a n d " > < C o l u m n s > < a s p : T e m p l a t e F i e l dH e a d e r T e x t = " E m p l o y e eN a m e " > < I t e m T e m p l a t e > < a s p : L i n k B u t t o n I D = " l n k n a m e " r u n a t = " s e r v e r " T e x t = ' < % # E v a l ( " E M P L O Y E E _ N A M E " )% > ' C o m m a n d A r g u m e n t = ' < % # E v a l ( " E M P L O Y E E _ I D " )+ " , " + E v a l ( " M A N A G E R _ I D " )% > ' C o m m a n d N a m e = " l i n k B u t t o n " > a s p : L i n k B u t t o n > I t e m T e m p l a t e > a s p : T e m p l a t e F i e l d > C o l u m n s > a s p : G r i d V i e w >

Transcend JetFlash 350 16 GB... List Price: Rs.990 Our Price: Rs.643

HTC A310E Explorer List Price: Rs.12990 Our Price: Rs.6690

Sony DSC-H100 Point & Shoot The Monk Who Sold His Ferrari List Price: Rs.195 Our Price: Rs.89 Our Price: Rs.10990

Blog Archive
2013 (161) 2012 (742) December (34) November (76) October (86) September (64) August (147) July (145) June (94) May (64) DataView.RowFilter() Vs DataTable.Rows.Find() Perf... DataTable.Select() Vs DataTable.Rows.Find() Perfor... DataTable.Select() Vs DataView.RowFilter() Perform... DataSet Vs DataReader Performance Test Loading a... Asp.Net designer file not updating (VS.Net 2008) LINQ to SQL Vs ADO.Net Performance Test

csharp-guide.blogspot.com/2012/05/gridview-commandargument-passing.html

1/3

29/11/13

GridView CommandArgument, passing multiple values | C# Guide - C#, Asp.Net, MVC, LINQ, jQuery and SharePoint Resources
C alling ... LINQ to SQL Vs ADO.Net Performance Test C alling ... LINQ to SQL Vs ADO.Net Performance Test DELETE LINQ to SQL Vs ADO.Net Performance Test UPDATE LINQ to SQL Vs ADO.Net Performance Test INSERT Asp.Net Performance Tuning LINQ to SQL Vs ADO.Net Performance Test Loading ... LINQ to SQL Vs ADO.Net Performance Test Loading ... Measure Execution time using Environment class Measure Execution time using Stopwatch class LINQ to SQL - call stored procedure with OUTPUT pa... LINQ to SQL - call stored procedure with parameter... LINQ to SQL - call stored procedure without parame... Asp.net C ustomValidator JavaScript client side v... Asp.net C ustomValidator - Server side validation C # break Vs continue Statement C # return Statement

Here is the code behind logic to receive the multiple values passed through the CommandArgument p r o t e c t e dv o i dg r d E m p l o y e e _ R o w C o m m a n d ( o b j e c ts ,G r i d V i e w C o m m a n d E v e n t A r g se ) { i n ti n t E m p I d=0 ; i n ti n t M g r I d=0 ; i f( e . C o m m a n d N a m e= =" l i n k B u t t o n " ) { s t r i n g [ ]c o m m a n d A r g s=e . C o m m a n d A r g u m e n t . T o S t r i n g ( ) . S p l i t ( n e wc h a r [ ] {' , '} ) ; i n t E m p I d=C o n v e r t . T o I n t 3 2 ( c o m m a n d A r g s [ 0 ] ) ; i n t M g r I d=C o n v e r t . T o I n t 3 2 ( c o m m a n d A r g s [ 1 ] ) ; } } Thats it we have now passed multiple values using the CommandArgument property and received the same in the RowCommand event of the code behind file.
Posted by Prakash B at 3:18 PM Labels: C ommandArgument, GridView, RowC ommand

Sony Cyber-shot DSC-S5000 Poi... List Price: Rs.4990 Our Price: Rs.4599 Samsung Galaxy S 2 I9100 List Price: Rs.29999 Our Price: Rs.25900

Philips GoGear ViBE 4 GB MP4... List Price: Rs.3999 Our Price: Rs.3790

Giordano Analog Watch - For Men List Price: Rs.5850 Our Price: Rs.1610

Assassin's Creed Our Price: Rs.1499

C # goto Statement C # continue Statement C # break Statement Line Break in JavaScript alert and codebehind fil... C heckBoxList Binding options Dynamically RadioButtonList Binding options Dynamically Adding RadioButton options Dynamically GridView C ommandArgument, passing multiple values LINQ to SQL Using ExecuteC ommand() to Execute SQ... LINQ to SQL DELETE LINQ to SQL UPDATE LINQ to SQL INSERT LINQ to SQL RIGHT OUTER JOIN LINQ to SQL LEFT OUTER JOIN

Search other Products: All Categories Search

LINQ to SQL INNER JOIN Excel - C olor row based on a Value Excel - C olor cell based on value Excel Dropdown in C ells LINQ to SQL Select with AGGREGATE (GROUP BY) LINQ to SQL Select with SORT (ORDER BY) LINQ to SQL Select DISTINC T Values LINQ to SQL Join 2 Tables LINQ to SQL - Sub Queries LINQ to SQL Select Query with Alias Name

No comments:
Post a C omment

Newer Post Subscribe to: Post Comments (Atom)

Home

Older Post

LINQ to SQL Select query with Filter (WHERE C lause... LINQ to SQL Select Query with Specific columns LINQ To SQL Vs ADO.Net Entity Framework Entity Data Model ADO.NET Entity Framework Architecture C onceptual Vs Logical Vs Physical Data Model Physical Data Model Logical Data Model C onceptual Data Model ADO.NET Entity Framework LINQ to SQL Sample Object Relational Designer (O/R Designer) LINQ to SQL DataTable SORT using LINQ DataTable Filter using LINQ Binding a DataTable to GridView GridView Filter using LINQ

csharp-guide.blogspot.com/2012/05/gridview-commandargument-passing.html

2/3

29/11/13

GridView CommandArgument, passing multiple values | C# Guide - C#, Asp.Net, MVC, LINQ, jQuery and SharePoint Resources
Binding a C # List to a GridView control April (23) March (9) 2009 (2)

About Me
Prakash B View my complete profile

Network Blog Directories

csharp-guide.blogspot.com/2012/05/gridview-commandargument-passing.html

3/3

Vous aimerez peut-être aussi