|
INTERVIEW QUESTIONS
MICROSOFT
DATAGRID
DETAILS
Question: 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?
Answer: 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
|
|
|
Category |
DataGrid Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7875 users |
Added on |
7/27/2011 |
Views |
73707 |
Rate it! |
|
|
Question:
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?
Answer:
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 Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All DataGrid Interview Questions & Answers - Exam Mode /
Learning Mode
|