•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,125 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,322 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3092 | Replies: 2
![]() |
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation:
Rep Power: 7
Solved Threads: 58
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.
•
•
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 196
Reputation:
Rep Power: 2
Solved Threads: 6
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
This should work. Please get back to me
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
Sub Grid_EmpCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) ' e.Item is the table row where the command is raised. ' For bound columns, the value is stored in the Text property of the TableCell. Dim empNoCell As TableCell = e.Item.Cells(1) Dim empnameCell As TableCell = e.Item.Cells(2) Dim empNo As String = empNoCell.Text Dim empName As String = empnameCell.Text 'Assign to the text boxes If CType(e.CommandSource, LinkButton).CommandName = "updateTextBoxes" Then textbox1.text = sEmpno textbox2.text = sEmpname
•
•
•
•
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 8:31 am.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- disabling datagrid hyperlink column underline (ASP.NET)
- hyperlink in a datagrid? (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Problem Inserting into SQL database on server
- Next Thread: quick question



Linear Mode