Showing posts with label grid. Show all posts
Showing posts with label grid. Show all posts

Wednesday, March 21, 2012

Problem with Grid View

i seem to have problems with my grid view not displaying anything when if i test my SQLDataSource, it shows me rows of data.

i seem to have this problem only with my Stored procedure, or when i change my Database structure, like add fields

Here is my procedure: can i do this? select a row and also return a varchar?

ALTER PROCEDURE dbo.SelectUpload(@.FileNamevarchar(50),@.Return varchar(MAX) =NULLOUTPUT)ASSELECT *FROM UploadsWHERE FileName = @.FileNameRETURNSELECT WebPathFROM UploadsWHERE FileName = @.FileName

Assuming that Webpath is a column in Uploads, why do you need the two select statements? When you do Select * from Uploads, Webpath will part of the dataset that the sqldatasource returns. Why can't you do:

ALTER PROCEDURE dbo.SelectUpload

@.FileNamevarchar(50)

AS
SELECT *FROM Uploads
WHERE FileName = @.FileName
RETURN

|||

i was thinking of returning a table to display in a Grid View, and also a Web Path (eg. "~/Images/image.jpg") to be displayed as a image, something like that. so that i don't have to retrieve it from the Data Source or Grid View.

|||

I still think you can grab all the data you need using one select statement and then do what you need to do with the data:

For the data you want displayed in the gridview:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="value1" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="value1" HeaderText="value1" ReadOnly="True" SortExpression="Value1" />
<asp:BoundField DataField="value2" HeaderText="value2" SortExpression="value2" />
<asp:BoundField DataField="value3" HeaderText="value3" SortExpression="value3" />
</Columns>
</asp:GridView>

For the webpath (lets say you want to display in a label):

Dim dv As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
Dim dr As DataRow
dr = dv.Table.Rows(0)
lblWebPath.Text = dr("WebPath").ToString()