help me in datagrid

Results 1 to 2 of 2

Thread: help me in datagrid

  1. #1
    Join Date
    Dec 1969

    Default help me in datagrid

    i use link button in datagrid&#039;s item template. when any user clicks on any item of datagrid then a method is invoked onclik event of link button. in the body of this method iam retriving other information about the item which is clicked from the database. know the problem is that i want to pass the value or text which is clicked as a parameter to the query which retrives information from the database.<BR><BR>the datagrid code is as follows<BR>&#060;/datagrid&#062;<BR>&#060;Columns&#062;<BR>&#060;asp :TemplateColumn HeaderText="BOOK NAME"&#062;<BR>&#060;ItemTemplate&#062;<BR>&#060;a sp:LinkButton id="linkbutton1" runat="server" Text=&#039;&#060;%# container.dataitem("bookname") %&#062;&#039; onclick="getinfo" CausesValidation="false"&#062;<BR>&#060;/asp:LinkButton&#062;<BR>&#060;/ItemTemplate&#062;<BR>&#060;/asp:TemplateColumn&#062;<BR>&#060;/Columns&#062;<BR>&#060;/asp:DataGrid&#062; <BR><BR>the onclick sub routine code is as follows<BR><BR> sub getinfo(obj as object, e as eventargs)<BR> dim objcmd as oleDbCommand = new oleDbCommand("select BookName,authorname from BooksTable where bookName=@book", conn)<BR><BR> dim objReader as OleDbDataReader<BR> dim objParam as OleDbParameter<BR> <BR> objparam=objcmd.parameters.add("@book",oledbtype.b str)<BR> objparam.direction=parameterdirection.input<BR> objparam.value= &#039;here i want to pass that selected item text <BR> <BR> try<BR> <BR> objCmd.Connection.Open()<BR> objReader = objCmd.ExecuteReader<BR> <BR> catch ex as OleDbException<BR> <BR> lb1.text="Error WHILE RETRIVING THE DATA FROM DataBase"<BR> <BR> end try<BR> <BR> datagrid2.DataSource = objReader<BR> DataBind()<BR> objReader.Close()<BR> objCmd.Connection.Close()<BR>end sub

  2. #2
    Join Date
    Dec 1969

    Default This might help

    I&#039;m not 100% sure that this will work, but you can try it out. Write your Sub like this: <BR>Sub getinfo(ByVal sender As Object, ByVal e As DataGridItemEventArgs)<BR><BR>Now try to get the info you need from the DataGrid with this line:<BR>e.Item.Cells(0).Text<BR>This will get the text from the first column in the DataGrid. Like I said, I&#039;m not sure if it will do the trick, but it works when using OnItemDataBound in the DataGrid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts