954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

get data from detailview

I have problem with detailview. My detail view like this:
ProductID: 1
ProductName: car
Price: 200
And when I click link button, it will appear "1"
This is the code behind:

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim detail As DetailsView = DetailsView1
        Dim rows As DataControlFieldCollection = detail.Fields
        Dim ProductID As DataControlField = rows.Item(1)
        Label1.Text = ProductID.ToString
   End Sub

But when I click link button, the text of label is "ProductID", not "1" like I want
Could you please help me? Thanks a lot!

donaldunca
Light Poster
27 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

hi,

i have no exp in details view.may be it can help

try like this

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand">
      <Fields>
      <asp:TemplateField>
      <ItemTemplate>
      <asp:LinkButton ID="lnk" runat="server" CommandArgument='<%#Eval("Productid") %>' ></asp:LinkButton>
      </ItemTemplate>
      </asp:TemplateField>
      </Fields>
        </asp:DetailsView>

protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "lnk")
        {
           string id = e.CommandArgument.ToString();
        }
    }
greeny_1984
Posting Whiz
372 posts since Apr 2007
Reputation Points: 25
Solved Threads: 29
 

hi,

sorry i fogot to add

<ItemTemplate>
      <asp:LinkButton ID="lnk" runat="server" CommandArgument='<%#Eval("Productid") %>'  CommandName="lnk"></asp:LinkButton>
      </ItemTemplate>
greeny_1984
Posting Whiz
372 posts since Apr 2007
Reputation Points: 25
Solved Threads: 29
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You