944,198 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 7032
  • ASP.NET RSS
Apr 23rd, 2007
0

datagrid hyperlink

Expand Post »
I have a datagrid in my webform with two columns namely empno and empname. The column empname is a hyperlink column. When the page loads both the columns are displaying data from the emp table. There are totally 5 records in the emptable. So five rows are getting displayed in the datagrid. Fine. There are other columns in the emptable namely salary and designation which should be displayed in the appropriate textboxes whenever a particular empname(Hyperlink column) for e.g "Ram" which is the second record in the grid is clicked. Similarly if the third record empname(hyperlink column) is clicked the salary details and designation details should be populated in the appropriate textboxes. How to achieve this? Pls help me with full coding. I am using vb.net
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crprajan is offline Offline
3 posts
since Apr 2007
Apr 23rd, 2007
0

Re: datagrid hyperlink

We need to see your code to be more helpful. But basically you need an event handler for the datagrids ItemCommand event. Use the DataGridItemEventArgs object that is passed as a parameter to the handler to determine which link was clicked and the empno it represents, query the database and populate the textboxes.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Apr 27th, 2007
0

Re: datagrid hyperlink

You need to do several things. This basically a break down of what Hollystyles suggested. Please pay close attention.
edit the html code and edit the Itemcommand property(add a command name)
[html]
<P><asp:datagrid id="dgFS" runat="server" Height="132px" Width="436px" CssClass="DefaultDataGridStyle"
OnItemCommand="Grid_EmpCommand" BorderWidth="0px" CellPadding="0" AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="#d7dce8"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn DataField="empNo" HeaderText="Emp No">
<HeaderStyle Font-Size="15px" Width="100px" Height="45px" BackColor="#6b83c6"></HeaderStyle>
<ItemStyle Font-Size="15px" Height="50px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="empname" HeaderText="Emp name">
<HeaderStyle Font-Size="15px" Width="100px" Height="45px" BackColor="#6b83c6"></HeaderStyle>
<ItemStyle Font-Size="15px" Height="50px"></ItemStyle>
</asp:BoundColumn>
<asp:ButtonColumn DataTextField="empname" ButtonType="LinkButton" HeaderText="empname" CommandName="updateTextBoxes">
<HeaderStyle Font-Size="15px" Font-Bold="True" Width="100px" Height="50px" BackColor="#6b83c6"></HeaderStyle>
<ItemStyle Font-Size="15px" Height="50px" BorderStyle="Groove" BorderWidth="9"></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid></

[/html]


This summarizes what you already have now just add the OnItemCommand="Grid_EmpCommand" to the datagrid and the
CommandName="updateTextBoxes" to the linkbutton. Open the code screen and add the following
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2.  
  3. Sub Grid_EmpCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
  4. ' e.Item is the table row where the command is raised.
  5. ' For bound columns, the value is stored in the Text property of the TableCell.
  6. Dim empNoCell As TableCell = e.Item.Cells(1)
  7. Dim empnameCell As TableCell = e.Item.Cells(2)
  8.  
  9. Dim empNo As String = empNoCell.Text
  10. Dim empName As String = empnameCell.Text
  11.  
  12. 'Assign to the text boxes
  13. If CType(e.CommandSource, LinkButton).CommandName = "updateTextBoxes" Then
  14. textbox1.text = sEmpno
  15. textbox2.text = sEmpname
  16.  
This should work. Please get back to me



Click to Expand / Collapse  Quote originally posted by crprajan ...
I have a datagrid in my webform with two columns namely empno and empname. The column empname is a hyperlink column. When the page loads both the columns are displaying data from the emp table. There are totally 5 records in the emptable. So five rows are getting displayed in the datagrid. Fine. There are other columns in the emptable namely salary and designation which should be displayed in the appropriate textboxes whenever a particular empname(Hyperlink column) for e.g "Ram" which is the second record in the grid is clicked. Similarly if the third record empname(hyperlink column) is clicked the salary details and designation details should be populated in the appropriate textboxes. How to achieve this? Pls help me with full coding. I am using vb.net
Last edited by jamello; Apr 27th, 2007 at 9:31 am.
Reputation Points: 215
Solved Threads: 6
Posting Whiz in Training
jamello is offline Offline
219 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Problem Inserting into SQL database on server
Next Thread in ASP.NET Forum Timeline: quick question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC