• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

dotnetnuke module to populate datbase contents dynamically

Hi,

I am new to asp.net and dotnetnuke.
I have created a dotnetmodule which pulls the data from the database and populates the contents in the gridview.  I need to make the contents of the gridview clickable in such a manner that it should populate another set of data onto another gridview control.

the table (softwares) schema is something like this

Product      version    Comaptiblity

abc            1.0           winxp
xyz            2.0           vista
abc            2.0           vista
xyz            3.0           winxp

onload i am able to populate the products and now what i need is when somebody clicks on the product (say abc) it should populate the versions available on the second gridveiw control.


===============================test.ascx======================================
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Test.ascx.vb" Inherits="DesktopModules_Test_Test" %>
Search:&nbsp;
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>&nbsp;
<asp:Button ID="btnSearch" runat="server" Text="Button" /><br />
<br /> 
<table><tr>
<td style="height: 154px">
<div class ="style5">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
    &nbsp;&nbsp;
</div>
</td>
<td style="height: 154px">
<div class ="style5">
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
    &nbsp;&nbsp;
</div></td>
</tr>
</table>
===============================test.ascx.vb===================================
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
 
Partial Class DesktopModules_Test_Test
    Inherits DotNetNuke.Entities.Modules.PortalModuleBase
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
          ' this function shows the available products on load
            ShowData("Product")
        End If
 
    End Sub
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        ShowData(txtSearch.Text)
    End Sub
    Private Sub ShowData(ByVal SearchString As String)
        Dim mySqlString As New StringBuilder()
        mySqlString.Append("SELECT DISTINCT ")
        mySqlString.Append(SearchString)
        mySqlString.Append(" FROM Softwares ")
        Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)
        myParam.Value = SearchString
        Me.GridView1.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)
        Me.GridView1.DataBind()
    End Sub
  
End Class

Open in new window

0
Shiva_Kumar
Asked:
Shiva_Kumar
  • 2
1 Solution
 
Shiva_KumarAuthor Commented:
Do I have any Suggestions?
0
 
paololabeCommented:
Is quite simple.
One way is to add a SELECT CommandField in the first gridview, you can do this from the vs wizard for gridView on EditColumns, then you have to manage the GridView event OnSlectedIndexChanged retreiving the selected data from GridView1.SelectedRow....

Should be something like the attached code, where the first cell contain the value passed to ShowData2 to filter data in GridView2

Hope this help,
Paolo.

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Test.ascx.vb" Inherits="DesktopModules_Test_Test" %>
Search: 
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox> 
<asp:Button ID="btnSearch" runat="server" Text="Button" /><br />
<br /> 
<table><tr>
<td style="height: 154px">
<div class ="style5">
<asp:GridView ID="GridView1" runat="server">
<Columns>
                
                <asp:CommandField ShowSelectButton="True" />
            </Columns>
</asp:GridView>
      
</div>
</td>
<td style="height: 154px">
<div class ="style5">
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
      
</div></td>
</tr>
</table>
===============================test.ascx.vb===================================
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
 
Partial Class DesktopModules_Test_Test
    Inherits DotNetNuke.Entities.Modules.PortalModuleBase
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
          ' this function shows the available products on load
            ShowData("Product")
        End If
 
    End Sub
 
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
GridViewRow row = GridView1.SelectedRow
ShowData2(row.Cells(0).Text);
)
    }
 
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        ShowData(txtSearch.Text)
    End Sub
    Private Sub ShowData(ByVal SearchString As String)
        Dim mySqlString As New StringBuilder()
        mySqlString.Append("SELECT DISTINCT ")
        mySqlString.Append(SearchString)
        mySqlString.Append(" FROM Softwares ")
        Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)
        myParam.Value = SearchString
        Me.GridView1.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)
        Me.GridView1.DataBind()
    End Sub
  
End Class

Open in new window

0
 
Shiva_KumarAuthor Commented:
Perfect!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now