Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Datagrid

  Asked By: Mada    Date: Oct 19    Category: Asp.net    Views: 667
  

I have a number of text fields on a page with a datagrid below the text fields. I want to populate the text fields with the first record in the datagrid when the page loads. Can anyone give me some directions on where to start?

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Betty White     Answered On: Oct 19

Could you include just a bit of code, namely how you are populating the
datagrid? (DataReader or DataSet or DataView) (VB, C#)

 
Answer #2    Answered By: Beverly Brooks     Answered On: Oct 19

Sorry for not supplying any information. You are suppose to know what I am doing. Right?

Heres some code that I use to populate  my datagrid. I am also using VB. Think this will be enough to give  you an idea of what I am doing. Thanks.


Sub Page_Load(Src As Object, E As EventArgs)
Dim ConnectString As String
MyConnect = New SqlConnection
connectString = ConfigurationSettings.AppSettings("ConnectStr")
MyConnect.ConnectionString = ConnectString
If Not IsPostBack Then
BindGrid()
End If
End Sub

public Sub BindGrid()
Dim MyCommand As SqlDataAdapter = New SqlDataAdapter ("Select * " _
& "From Users", MyConnect)
Dim ds As DataSet = New DataSet()
MyCommand.Fill(ds)
MyDataGrid.DataSource=ds
MyDataGrid.DataBind()
End Sub

 
Answer #3    Answered By: Adelfrid Fischer     Answered On: Oct 19


public Sub BindGrid()
Dim MyCommand As SqlDataAdapter = New SqlDataAdapter ("Select *
" _
& "From Users", MyConnect)
Dim ds As DataSet = New DataSet()
MyCommand.Fill(ds)
MyDataGrid.DataSource=ds
MyDataGrid.DataBind()

Dim dr as datarow = ds.tables(0).Rows(0)
'at this point, dr contains the first row from the datatest
TextBox1.text = dr("ColumnName").ToString()

'And so forth


End Sub

 
Answer #4    Answered By: Barabas Cohen     Answered On: Oct 19

I know its a lovely topic for all but its driving me crazy.

I created a datagrid  via the Data Form Wizard but the column I chose to do
sorting on does nothing when you click it. All the examples I have seen look
like they were for datagrids that were not created using the wizard and I am
having problems trying to engineering them to work in the code generated by the
wizard.

Any help in the right direction would be wonderful.

 
Answer #5    Answered By: Stefan Thompson     Answered On: Oct 19

did you set the allow sorting property?

 
Answer #6    Answered By: Ivan Coleman     Answered On: Oct 19

Just a thought but do all of the columns you are trying to sort on have valid
data? You may run into problems if there are nulls or odd characters.

 
Answer #7    Answered By: Jet Brown     Answered On: Oct 19

I only have 1 column enabled at the moment (last name) and all the rows have a
valid value in that field.

 
Didn't find what you were looking for? Find more on Datagrid Or get search suggestion and latest updates.




Tagged: