aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" in

Jun 3, 2012

In this article I will explain alternative of CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" in
In Previous article I explained move gridview rows up and down in during work with that one I mentioned
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" for button it worked perfectly with C# code and I tried to use same CommandArgument code in VB.NET but it doesn’t work for me for that I used another way like this CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" then my problem got solved with

Check below code differences for C# and VB.NET

C# Code

<asp:TemplateField HeaderText="Location">
<asp:Button ID="btnUp" CommandName="Up" ToolTip="UP" Text="&uArr;" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" /> </ItemTemplate>

<asp:TemplateField HeaderText="Location">
<asp:Button ID="btnUp" CommandName="Up" ToolTip="UP" Text="&uArr;" runat="server" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" />

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

How to pass the value of the control id(another cntrol inside the grid) of the datagrid on the onclientclick event to javascript function. So that i can use that value and do a conditional check there.

serach said...

I still got the CommandArgument problem, but this article is really helpful.

Jas Kumar said...

hello i have bind gridview using session my now i wand to delete row form that grid. my code is.

Page (Binddetail.aspx)

protected void ImageButton4_Click(object sender, ImageClickEventArgs e)

DataSet ds = null;
if (Session["sCart"] == null)
ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Product_Code", typeof(System.Int32)));
dt.Columns.Add(new DataColumn("Product_Name", typeof(System.String)));
dt.Columns.Add(new DataColumn("Qty", typeof(System.Int32)));
dt.Columns.Add(new DataColumn("Price", typeof(System.Int32)));
dt.Columns.Add(new DataColumn("Total_Price", typeof(System.Int32)));
Session["sCart"] = ds;
ds = (DataSet)Session["sCart"];
DataRow row = ds.Tables[0].NewRow();
row["Product_Code"] = lblpcode.Text;
row["Product_Name"] = lblpname.Text;
row["Qty"] = TextBox1.Text;
row["Price"] = lblprice.Text;
row["Total_Price"] = Convert.ToInt32(TextBox1.Text) * Convert.ToInt32(lblprice.Text);



// now i at mycart.aspx page i am bind the grid

// code is //

GridView1.DataSource = (DataSet)Session["sCart"];

please help me how can i delete the gridview data....

tyrtyrtyrtyrtyrtyrtytrytry said...

CommandArgument='<%# Container.DataListItem %>'

Cool said...


Unknown said...

thank u suresh....

sumitha jaganathan said...

Thank u so much..

Anonymous said...


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.