Introduction:
In this article I will explain alternative of CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" in vb.net.
Check below code differences for C# and VB.NET
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
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="⇑"
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="⇑"
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. |
|||
|
|||
8 comments :
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.
I still got the CommandArgument problem, but this article is really helpful.
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....
CommandArgument='<%# Container.DataListItem %>'
WOW
thank u suresh....
Thank u so much..
thanks
Note: Only a member of this blog may post a comment.