Hi, How to sort the data in Datagrid ? when we use DataBound event of Datagrid, I want to display te data using controls.... For an example, If i click a button, which is outside of the datagrid, entire data should be shown. 1st column in TextBoxs. second column in Drop down List Boxs.. How to bind the data in Dropdownlist,which is in DataGrid at run time? Row1 Row2 Row3 Row4 ----------------- This is the record in datagrid... When we click button (Bottom of the DataGrid), This Record should be shown... Row1 in TextBox,,, Row2 in TextBox, Row3 in DropDownlistbox, Row4 in TextBox... How to do this one? Which event we should use?... Please let me know the code for this ... Thanks in Advance... Ravi Majji

Questions by aspnet

Showing Answers 1 - 2 of 2 Answers

Makesh. R

  • Jul 25th, 2006

Hi Friends,Sorting in DataGrid.Using the SortCommand Event in the datagrid u can sort the value in datagrid.For Example.Dim con as new oledb.oledbconnection("connectionstring")con.open()Dim sql as stringsql="query"Dim DataAdapter as new oledb.oledbdataadapter(sql,con)dim ds as new datasetdataadapter.fill(ds)Private Sub DGMain_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DGMain.SortCommand Dim datasort As DataView datasort = LocalLibrary.GetDataSet(sql).Tables(0).DefaultView datasort.Sort = e.SortExpression DGMain.DataSource = datasort DGMain.DataBind() End SubBind the data in Datagrid at runtime ?Use ItemDataBound Event in datagrid.Private Sub DGMain_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGMain.ItemDataBound If e.Item.ItemIndex > -1 Then Dim lblClose As dropdownlist lblClose = CType(e.Item.FindControl("lblClose"), dropdownlist) If Not lblClose Is Nothing Then lblclose.items.add("dropdownassignvalue")lblclose.items("dropdownindex").value="assigned value" End If End If End Sub

  Was this answer useful?  Yes


  • Oct 26th, 2006

Hi,In order to sort the data in the datagrid apply rowFilters. . . This can be done by using either a DataView or a DataTable. The data that we get from the database is stored in the tables and dataview which allow us to work with the data instead of making trips to the server. For instance SqlCommand cmd=new SqlCommand();SqlDataAdapter da=new SqlDataAdapter();DataView dView;DataSet ds = new DataSet();cmd.Connection=con;cmd.commandText = "Select * from emp";da.selectCommand = cmd;da.fill(ds,"emp");dView = ds.Tables["emp"].DefaultView;dView.Sort = " Age asc";By applying the sort filter as stated above you can sort your values.. . . . . .Thanks & Regards PavanKumar Sriramula

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions