How to: Load data in gridview without DataSource

I

ircremer

Hello,

First, sorry for my English...

I'm triying to load data from store procedure into a gridview.

The most simply is doing 'myGrid.DataSource = myDataTable', but this
'myDataTable' returns a numeric value that I need to transform (this
numeric value is an ID, and i need the description of this ID, that is
store in another table in my DB)

My Gridview has 3 BoundsFields and one TemplateField for this
'problematic' column, whit a Label:

<Columns>
<asp:BoundField DataField="xxxx" HeaderText="xxxx" />
<asp:TemplateField HeaderText="xxxx">
<ItemTemplate>
<asp:Label ID="xxxx" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
...

I need a idea, because I'm looking for it in google and msdn but no
'good results'... (in ASP .NET)

Thanks.

Now In Spanish:

Hola,

Estoy intentando cargar los datos de un procedimiento almacenado en un
gridview. Obviamente lo más sencillo es hacer un 'gridview.DataSource
= myDataTable' y que lo haga automáticamente. El problema es que la
consulta ejecutada, me devuelve un campo ID que tendria que
transformar en su descripcion para poder mostrar eso al usuario.

Como se detalla arriba, uso un gridview con BoundsFields para los
campos que no necesito tocar, y un TemplateField para este campo, ya
que no busco asignarlo directamente de la BD.

Necesito alguna idea porque todo lo que he buscado por google y msdn
no indica nada parecido para resolverlo. (en ASP . NET)

Gracias.
 
L

luukas9

Thanks for your response, and sorry for my error... I'm not habit for
this site...

Your response isn't that I'm looking for... but thanks.

I'll move my question for the asp .net group.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Is myDataTable really a DataTable? if so it returns a table, not a value.

What you can do is in the SP add another column for the value of that ID:

select product.*, category.Name from products P inner join Category C on
P.categoryID = C.Id

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Hello,

First, sorry for my English...

I'm triying to load data from store procedure into a gridview.

The most simply is doing 'myGrid.DataSource = myDataTable', but this
'myDataTable' returns a numeric value that I need to transform (this
numeric value is an ID, and i need the description of this ID, that is
store in another table in my DB)

My Gridview has 3 BoundsFields and one TemplateField for this
'problematic' column, whit a Label:

<Columns>
<asp:BoundField DataField="xxxx" HeaderText="xxxx" />
<asp:TemplateField HeaderText="xxxx">
<ItemTemplate>
<asp:Label ID="xxxx" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
....

I need a idea, because I'm looking for it in google and msdn but no
'good results'... (in ASP .NET)

Thanks.

Now In Spanish:

Hola,

Estoy intentando cargar los datos de un procedimiento almacenado en un
gridview. Obviamente lo más sencillo es hacer un 'gridview.DataSource
= myDataTable' y que lo haga automáticamente. El problema es que la
consulta ejecutada, me devuelve un campo ID que tendria que
transformar en su descripcion para poder mostrar eso al usuario.

Como se detalla arriba, uso un gridview con BoundsFields para los
campos que no necesito tocar, y un TemplateField para este campo, ya
que no busco asignarlo directamente de la BD.

Necesito alguna idea porque todo lo que he buscado por google y msdn
no indica nada parecido para resolverlo. (en ASP . NET)

Gracias.
 
L

luukas9

Hi.

myDataTable exist in my file xsd. The problem I have with your
solution is that:

Table: Employee
Fields: IDEmployee (int), Name (varchar), Surname (varchar),
IsBoss (varchar), IDEmployeeBoss (int)

In my SELECT, I filter by IDEmployee. When I execute the store
procedure, it returns {1,'name01', 'surname01', false, 2} {2,'boss01',
'surname02',true, null}.

Then, in the case that I'll need the boss name y need to do something
(a new select filter by IDBoss) to get the boss name.

Temporarily, I've found a solution that consist in:
myDataTableResult.Rows["IDEmployee"] =
SelectBossName(myDataTableResult.Rows
["IDEmployee"].toString()).toString(); that modifies the return value
for this column with a new select that retries the boss name.

But the problem persist, because, it's only a temporarily solution.

Thanks for your response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top