Access asp:SqlDataSource or asp:GridView directly

  • Thread starter Thread starter saturnius
  • Start date Start date
S

saturnius

Hello, I have to save the data from a gridview as XML file. The code is
shown below. Is there no easier way? I would like to access either
asp:SqlDataSource (me.SqlDataSource1.something) or asp:GridView
(me.GridView1.something) instead I have to create a new
sqlcon,selectcommand,dataset,dataadapter....

Is there no easier way?



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

'too much code?

Dim conSave As New
System.Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
conSave.Open()
Dim strSQL As String
Dim dsSave As New Data.DataSet
Dim daSave As New Data.SqlClient.SqlDataAdapter
strSQL = Me.SqlDataSource1.SelectCommand.ToString
daSave.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL,
conSave)
daSave.Fill(dsSave)

'too much code!

dsSave.WriteXml("C:\SomeXMLFile.xml")
End Sub
 
Saturnius

I don't see any GridView in your code?
You are saving a file that you have got from a database.

Cor
 
Hello Cor,
I just jused drag and drop in Visual Web developer for
asp:SqlDataSource and asp:GridView - nothing else. The code behind a
button is shown above. I am just looking for a better solution to save
the xml file based on the gridview. But I can not figure out how to
access the gridview that I have on my page, instead I have to pull the
data again from the db. I would like to replace the code between my
comments by accessing the gridview/sqldatasource.

Thanks,
Saturnius
 
Saturnius,

I know no other answer that putting the data you put in your gridview in
advance in a seesion.
Than you can interact with the key presses or what else with that gridview.

The session gives you than the current data in the gridview.

Cor
 
Hi Cor,
thank you for the answer. I guess I will stick with my "pulling twice"
.....

Thanks!
Saturnius
 
Back
Top