Aspdotnet-Suresh

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

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

Jun 3, 2012
Introduction

In this article I will explain alternative of CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" in vb.net.
Description:
  
In Previous article I explained move gridview rows up and down in asp.net 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 vb.net

Check below code differences for C# and VB.NET

C# Code

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

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

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

Get the latest Asp.net, C#.net, 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

8 comments :

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.

Unknown 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)));
ds.Tables.Add(dt);
Session["sCart"] = ds;
}
else
{
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);


ds.Tables[0].Rows.Add(row);
Response.Redirect("mycart.aspx");

}


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

// code is //

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


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

tyrtyrtyrtyrtyrtyrtytrytry said...

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

Cool said...

WOW

Unknown said...

thank u suresh....

sumitha jaganathan said...

Thank u so much..

Anonymous said...

thanks

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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