Click here to Skip to main content
15,886,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview. When i click on a particular row of gridview,I want to display that rows information in datalist. I dont want to use any extra select button or something for selecting the particular row.Just click on the row of grid.How can i do this?

Can this be done by using selected index changed event of grid or any other event?
Posted
Updated 25-Nov-13 23:26pm
v4
Comments
Karthik_Mahalingam 26-Nov-13 4:02am    
datalist is a data repeater control to display more than 1 items..
instead of datalist, you can use some container control to display the row data.
you can use javascript to do the above....

Hi,

You can use JQuery to Append some Table or Div to show the details.

Add Click Event : http://api.jquery.com/click/[^]
Append DOM Object: http://api.jquery.com/append/[^]
 
Share this answer
 
Refer the This Link[^], there you will be demonstrated properly that how to bind you data list view by clickin on any row without auto generated select button. Further you can also visit this link[^] also.
 
Share this answer
 
As you click on select of gridview the selected row appears on datalist.
SQL
BookId Bookname Price
------Gridview-----
Select B1 Asp 1200
Select B2 Java 700
Select B3 C# 690
Select B4 PHP 659
Select B5 unix 865

---Datalist----
BookId: B3
Bookname: C#
Price: 690


Use two sqldatasource control, sqldatasource for datalist must have parameterize select command, then set the selectparameters. Example shows every things below:

XML
<form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="BookId" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="BookId" HeaderText="BookId" ReadOnly="True"
                    SortExpression="BookId" />
                <asp:BoundField DataField="Bookname" HeaderText="Bookname"
                    SortExpression="Bookname" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:BookDetailConnectionString %>"
            SelectCommand="SELECT * FROM [Books]">


            </asp:SqlDataSource>
        <br />
        <asp:DataList ID="DataList1" runat="server" DataKeyField="BookId"
            DataSourceID="SqlDataSource2">
            <ItemTemplate>
                BookId:
                <asp:Label ID="BookIdLabel" runat="server" Text='<%# Eval("BookId") %>' />
                <br />
                Bookname:
                <asp:Label ID="BooknameLabel" runat="server" Text='<%# Eval("Bookname") %>' />
                <br />
                Price:
                <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
                <br />
                <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server"
            ConnectionString="<%$ ConnectionStrings:BookDetailConnectionString2 %>"
            SelectCommand="SELECT * FROM [Books] where Bookid=@bookid"  >

           <SelectParameters>
           <asp:ControlParameter ControlID="GridView1" Name="bookid" PropertyName="SelectedValue" />
           </SelectParameters>


            </asp:SqlDataSource>

    </div>
    </form>
 
Share this answer
 
Comments
pwavell 26-Nov-13 7:12am    
Dont want to use select button to select.just left click on grid row and data should display.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900