get data from detailview

Reply

Join Date: Sep 2006
Posts: 27
Reputation: donaldunca is an unknown quantity at this point 
Solved Threads: 0
donaldunca's Avatar
donaldunca donaldunca is offline Offline
Light Poster

get data from detailview

 
0
  #1
Mar 12th, 2009
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:
  1. Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
  2. Dim detail As DetailsView = DetailsView1
  3. Dim rows As DataControlFieldCollection = detail.Fields
  4. Dim ProductID As DataControlField = rows.Item(1)
  5. Label1.Text = ProductID.ToString
  6. 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!
Last edited by donaldunca; Mar 12th, 2009 at 4:54 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: get data from detailview

 
0
  #2
Mar 12th, 2009
hi,

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

try like this

  1. <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand">
  2. <Fields>
  3. <asp:TemplateField>
  4. <ItemTemplate>
  5. <asp:LinkButton ID="lnk" runat="server" CommandArgument='<%#Eval("Productid") %>' ></asp:LinkButton>
  6. </ItemTemplate>
  7. </asp:TemplateField>
  8. </Fields>
  9. </asp:DetailsView>
  10.  
  11. protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
  12. {
  13. if (e.CommandName == "lnk")
  14. {
  15. string id = e.CommandArgument.ToString();
  16. }
  17. }
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: get data from detailview

 
0
  #3
Mar 12th, 2009
hi,

sorry i fogot to add
  1. <ItemTemplate>
  2. <asp:LinkButton ID="lnk" runat="server" CommandArgument='<%#Eval("Productid") %>' CommandName="lnk"></asp:LinkButton>
  3. </ItemTemplate>
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum


Views: 572 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC