Solved

Populate Devexpress Gridview on the selection of another gridview using sqldatsource

Posted on 2010-08-27
3
6,357 Views
Last Modified: 2012-05-10
Hi Experts,

I have a devexpress gridview bound to sqldatasource. On the selection of a row in this grid I want to pass student Matric No to second Dexexpress gridview so that it gets populate too with student data. I can get the Matric no, from the selected row but the problem I am having is to pass the selected Matric No as a parameter to the second Gridview. Any ideas how can we pass on this parameter
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="ds_Student"

                        KeyFieldName="MatricNo" ClientInstanceName="grid" OnCustomCallback="ASPxGridView1_CustomCallback">

                        <Columns>

                           <dx:GridViewCommandColumn VisibleIndex="3">

                                <SelectButton Text="select" Visible="True">

                                </SelectButton>

                            </dx:GridViewCommandColumn>

                            <dx:GridViewDataTextColumn FieldName="MatricNo" ReadOnly="True" VisibleIndex="0">

                            </dx:GridViewDataTextColumn>

                            <dx:GridViewDataTextColumn FieldName="Forename" VisibleIndex="1">

                            </dx:GridViewDataTextColumn>

                            <dx:GridViewDataTextColumn FieldName="Surname" VisibleIndex="2">

                            </dx:GridViewDataTextColumn>

                        </Columns>

                        <ClientSideEvents  SelectionChanged="function(s, e) {

	                    if (e.isSelected)

                    {

                        grid.PerformCallback(e.visibleIndex.toString());

                    }



                    }" />

                    </dx:ASPxGridView>

                    <asp:SqlDataSource ID="ds_Student" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>"

                        SelectCommand="SELECT [MatricNo], [Forename], [Surname], [Gender] FROM [Student]">

                    </asp:SqlDataSource>





<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"  DataSourceID="ds_StudentDetail"

                >

            <Columns>

                <dx:GridViewDataDateColumn FieldName="DateOfBirth" VisibleIndex="0">

                </dx:GridViewDataDateColumn>

                <dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="1">

                </dx:GridViewDataTextColumn>

                <dx:GridViewDataTextColumn FieldName="Telephone" VisibleIndex="2">

                </dx:GridViewDataTextColumn>

            </Columns>

        </dx:ASPxGridView>

        </ContentTemplate>

        </asp:UpdatePanel>

        <asp:SqlDataSource ID="ds_StudentDetail" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>  "

            SelectCommand="SELECT [DateOfBirth], [Email], [Telephone] FROM [Student] WHERE ([MatricNo] = @MatricNo)" >

            <SelectParameters>

             <asp:SessionParameter SessionField="MatricNo" Name="MatricNo"></asp:SessionParameter>

            </SelectParameters>

        </asp:SqlDataSource>





Code Behind is 



  protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)

    {

        int index = Convert.ToInt32(e.Parameters);



        string[] fieldNames = { "MatricNo", "Surname" };

        object[] values = (object[])((ASPxGridView)sender).GetRowValues(index, fieldNames);





       Session["MatricNo"] = Convert.ToInt32(values[0]);

        ASPxGridView1.DataBind();



    }

Open in new window

<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="ds_Student"

                        KeyFieldName="MatricNo" ClientInstanceName="grid" OnCustomCallback="ASPxGridView1_CustomCallback">

                        <Columns>

                           <dx:GridViewCommandColumn VisibleIndex="3">

                                <SelectButton Text="select" Visible="True">

                                </SelectButton>

                            </dx:GridViewCommandColumn>

                            <dx:GridViewDataTextColumn FieldName="MatricNo" ReadOnly="True" VisibleIndex="0">

                            </dx:GridViewDataTextColumn>

                            <dx:GridViewDataTextColumn FieldName="Forename" VisibleIndex="1">

                            </dx:GridViewDataTextColumn>

                            <dx:GridViewDataTextColumn FieldName="Surname" VisibleIndex="2">

                            </dx:GridViewDataTextColumn>

                        </Columns>

                        <ClientSideEvents  SelectionChanged="function(s, e) {

	                    if (e.isSelected)

                    {

                        grid.PerformCallback(e.visibleIndex.toString());

                    }



                    }" />

                    </dx:ASPxGridView>

                    <asp:SqlDataSource ID="ds_Student" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>"

                        SelectCommand="SELECT [MatricNo], [Forename], [Surname], [Gender] FROM [Student]">

                    </asp:SqlDataSource>





<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"  DataSourceID="ds_StudentDetail"

                >

            <Columns>

                <dx:GridViewDataDateColumn FieldName="DateOfBirth" VisibleIndex="0">

                </dx:GridViewDataDateColumn>

                <dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="1">

                </dx:GridViewDataTextColumn>

                <dx:GridViewDataTextColumn FieldName="Telephone" VisibleIndex="2">

                </dx:GridViewDataTextColumn>

            </Columns>

        </dx:ASPxGridView>

        </ContentTemplate>

        </asp:UpdatePanel>

        <asp:SqlDataSource ID="ds_StudentDetail" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>  "

            SelectCommand="SELECT [DateOfBirth], [Email], [Telephone] FROM [Student] WHERE ([MatricNo] = @MatricNo)" >

            <SelectParameters>

             <asp:SessionParameter SessionField="MatricNo" Name="MatricNo"></asp:SessionParameter>

            </SelectParameters>

        </asp:SqlDataSource>





Code Behind is 



  protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)

    {

        int index = Convert.ToInt32(e.Parameters);



        string[] fieldNames = { "MatricNo", "Surname" };

        object[] values = (object[])((ASPxGridView)sender).GetRowValues(index, fieldNames);





       Session["MatricNo"] = Convert.ToInt32(values[0]);

        ASPxGridView1.DataBind();



    }

Open in new window

0
Comment
Question by:mmalik15
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
puru1981 earned 500 total points
ID: 33540478
you can do this using dataset,datatables and relation. see the link below.

in example combobox is used you can use the gridview similarly.

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26411173.html
0
 

Author Comment

by:mmalik15
ID: 33540519
Thanks for the comment.
I am specificallly looking for the DevExpress Gridviews. And sorry that example does not seem to be relevant



0
 
LVL 9

Expert Comment

by:puru1981
ID: 33541496
i am talking here about dataset, datatable and datarelation. Forget about the other things.

you can see the datarelation easing the development in 3rd solution provided in this link

http://www.emoreau.com/Entries/Articles/2007/01/Setting-a-masterdetail-relationship-between-two-ComboBox.aspx

by using relation you can get the child rows from table2 depending on the foreign key column in table1 while creating the relation.

in devexpress gridviews you also set the datasource property to see the grid populated.

can you give me the code so that i can make it happen for you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
visual Basic Net vs c# net 8 56
Limiting string to two deciamls 18 36
String manipulation 15 49
Open a word document 23 19
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now