Hi
It is very important to select an item from data grid and show that in a text box. This us common in sales, purchase etc
See the new items in gridview for this activity highlighted in blue.
-------------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default5.aspx.vb" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome to Admin Home
</div>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
selectedindex="1"
onselectedindexchanged="GridView2_SelectedIndexChanged"
onselectedindexchanging="GridView2_SelectedIndexChanging" >
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Rollno" HeaderText="Rollno"
SortExpression="Rollno" />
<asp:ImageField DataImageUrlField="filepath" ControlStyle-Width="100"
ControlStyle-Height = "100" HeaderText = "Preview Image"/>
<asp:ButtonField Text="Click" CommandName="Select" ItemStyle-Width="30" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Name], [Rollno], [filepath] FROM [tblReg]" >
</asp:SqlDataSource>
<asp:TextBox ID="hupitem" runat="server"></asp:TextBox>
<br />
</form>
</body>
</html>
--------------------------------------------------------Code -------------------------
Partial Class Default5
Inherits System.Web.UI.Page
Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
hupitem.Text = GridView2.SelectedRow.Cells(1).Text
End Sub
Protected Sub GridView2_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView2.SelectedIndexChanging
hupitem.Text = GridView2.SelectedRow.Cells(1).Text
End Sub
End Class
---------------------------------------------------------Screen--------------------------------------