3

I am working on ASP.net 4.0 integrated with Oracle 10.2.0.4

This is my code for GridView and its SqlDatasource

<asp:GridView ID="gvRegNumber" runat="server" AutoGenerateColumns="False" DataSourceID="DsRegNumberGrid"
            Width="100%" AllowPaging="True" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid"
            BorderWidth="3px" CellSpacing="2" ForeColor="Black" PageSize="3" 
            CssClass="mGrid" onrowcommand="gvRegNumber_RowCommand" >
            <Columns>
                <asp:BoundField DataField="Registration No." HeaderText="Registration No." SortExpression="Registration No." />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
                <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
                <asp:BoundField DataField="From Date" HeaderText="From Date" SortExpression="From Date" />
                <asp:BoundField DataField="To Date" HeaderText="To Date" SortExpression="To Date" />
                         <asp:TemplateField>
                <EditItemTemplate>
                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/Themes/Icons/edit_icon.png"
                        ToolTip="Update" Height="20px" Width="20px" />
                </EditItemTemplate>
                <HeaderTemplate>
                    <asp:Label ID="Edit" Text="Edit" runat="server"></asp:Label>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="EditRow" CssClass="mGrid-edit" ImageUrl="~/Themes/Icons/edit_icon.png"
                        runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    <asp:Label ID="Delete" Text="Edit" runat="server"></asp:Label>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="DeleteRow" CssClass="mGrid-delete" ImageUrl="~/Themes/Icons/delete_icon.png"
                        runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>

        </asp:GridView>
        <asp:SqlDataSource ID="DsRegNumberGrid" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT &quot;fkEnumerationId&quot; AS &quot;Registration No.&quot;, &quot;Text&quot; AS &quot;Name&quot;, &quot;AdditionalValueText&quot; AS &quot;Make&quot;, &quot;AdditionalValue&quot; AS &quot;Model&quot;, &quot;IsActive&quot; AS &quot;Status&quot;, &quot;CreatedOn&quot; AS &quot;From Date&quot;, &quot;LastUpdatedOn&quot; AS &quot

;To Date&quot; FROM &quot;EnumerationValue&quot;">
    </asp:SqlDataSource>

I just want to have separate Datasource for separate columns in my grid. Is that possible? If so, how?

Thanks in advance.

  • 2
    Can you describe the use case of your requirement? It doesn't make sense why you'd want a column from a different datasource as such. And even if that is so, how do you want a user to interact with one such grid? Or, could you mean something like a [master-detail](http://en.wikipedia.org/wiki/Master%E2%80%93detail_interface) relationship? – deostroll Apr 25 '14 at 05:40
  • There are 3 columns in my grid depending on each other. Problem is the three columns are coming from a single table. If different tables were available or I could use any dropdown or textbox, it would be easy. But they are column themselves. How can I check them in a single query? – Khurram Zulfiqar Ali Apr 25 '14 at 05:49
  • EnumerationValue is the table name. lets say col 1, col 2 or col 3 are in grid. If col1_ID=1 then col2_ID=3, now if col2_ID=3 then col3_ID=5... this is the scenario. – Khurram Zulfiqar Ali Apr 25 '14 at 05:51
  • Plz share some info on that table design and a sample output you are expecting. (In the body of your question itself). – deostroll Apr 25 '14 at 05:54

3 Answers3

3

you can do this in your SP

select en1.text as 'Country', en2.text as 'City',en3.text as 'Region'  from
EnumValue en1, EnumValue en2, EnumValue en3
where en1.id = en2.[fkEnumeration] and en3.[fkEnumeration] = en2.id  and 
en1.id='yourid' ;
Muneeb Zulfiqar
  • 1,003
  • 2
  • 13
  • 31
1

try this in your Stored Procdure:

declare @temp_tbl TABLE (North varchar(10), South varchar(10))
insert into @temp_tbl TABLE(North)
select Text from table_name where Text='North'
insert into @temp_tbl(South)
select Text from table_name where Text='South'
Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
0

This is what I understood from your requirement "you want a grid that will dynamically change its column values or you have to bind the grid dynamically not just by DB incoming data." In that case, on page load event, you can create a table dynamically and add whatever controls you want. In that case you can add events too (textChange, selectedindexchange etc). Suppose you have 10 users and for each user you have to get the address. So you may have first column for country drop down, in second column you may have a state drop down and in third column you may have a city drop down and all are run-time linked to each other. If you have such requirement then I will suggest you to go for dynamic table generation instead of grid.

Amnesh Goel
  • 2,617
  • 3
  • 28
  • 47