Advertisement

02.20.2008 at 12:56PM PST, ID: 23179146
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Adding a Template Column on a Datatable bound GridView

Tags: VB.NET, ASP.NET
Hello experts,

I have a gridview that is bound to a Datatable.  The Autogenerate columns is set to "True".  on the gridview, I want to add an extra column that contains an "Edit Record" button.  When the button is clicked, I want it to call the "Popup_Edit_Window" javascript function and pass the value in the "Table_Name" column as a parameter.

How can I do this?

Thanks,
Paolo
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
<!-- Imported .NET Namespaces -->
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
 
<!-- User Controls -->
<%@ Register TagPrefix="Common" TagName="Header" Src="Header.ascx" %>
 
<%@ Page Language="VB" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
    'Global variables
    Dim conn As SqlConnection
    Dim daMaster As SqlDataAdapter
    Dim dsMaster As DataSet = New DataSet()
    Dim strWHERE as String
    
    Sub Page_Load()
        conn = New SqlConnection(ConfigurationManager.ConnectionStrings("MyDB").ConnectionString)
        If Not Page.IsPostBack Then
            Call Populate_Lookups()
            Call Load_Master_Grid()
        End If
        
    End Sub
    
    Sub Load_Master_Grid()
        Dim strSQL As String
        
        strSQL = ""
        strSQL = strSQL & "SELECT * from information_schema.tables "
   
        'where clause
        Call Set_Filter()
        strSQL = strSQL & strWHERE
        
        If hdn_gridMaster_Sort_Column.Value > "" Then
            strSQL = strSQL & " ORDER BY " & hdn_gridMaster_Sort_Column.Value & " " & hdn_gridMaster_Sort_Order.Value
        Else 'default sort order   
            strSQL = strSQL & " ORDER BY table_name"
        End If
        
        'Response.Write(strSQL)
        
        'save sql to be use to export data to excel
        'Session("ExportSQL") = "SELECT dsg_billing_system_name as 'BS',dsg_division_name as 'Division',dsg_site_name as 'Site',dsg_site_description as 'Site Name',campaign_code as 'Campaign Code',marketing_name as 'Desc',dt_marketing_start_sell_date as 'Start Date',dt_marketing_end_sell_date as 'End Date',case corporate when 1 then 'Yes' else 'No' end as 'Corporate' FROM list_campaign " & strWHERE & " order by dsg_division_name,dsg_site_description,campaign_code "
 
        'Response.Write(strSQL)
        'create the temporary Datatable
        daMaster = New SqlDataAdapter(strSQL, conn)
        daMaster.Fill(dsMaster, "dtMaster")
      
        gridMaster.DataSource = dsMaster.Tables("dtMaster")
        gridMaster.DataBind()
      
        
        'delete the datatable
        If dsMaster.Tables.CanRemove(dsMaster.Tables("dtMaster")) Then
            dsMaster.Tables.Remove("dtMaster")
        End If
    End Sub
   
   Sub Populate_Lookups()
        Dim strSQL As String
        
        ''***************************************
        ''* Populate Lookup 1
        ''***************************************
        
        strSQL = "select distinct table_type from INFORMATION_SCHEMA.tables ORDER BY table_type"
        
        'create the temporary Datatable
        daMaster = New SqlDataAdapter(strSQL, conn)
        daMaster.Fill(dsMaster, "dtLookup1")
        
        filter_table_type.DataSource = dsMaster.Tables("dtLookup1")
        filter_table_type.DataValueField = "table_type"
        filter_table_type.DataTextField = "table_type"
        filter_table_type.Items.Clear()
        filter_table_type.Items.Add(New ListItem("", ""))
        filter_table_type.DataBind()
        
        'delete the datatable
        If dsMaster.Tables.CanRemove(dsMaster.Tables("dtLookup1")) Then
            dsMaster.Tables.Remove("dtLookup1")
        End If
  
    End Sub
 
    Sub Set_Filter()
       
        If RTrim(filter_table_type.SelectedValue) > "" Then
            strWHERE = strWHERE & " table_type = '" & filter_table_type.SelectedValue & "' AND"
        End If
 
        If RTrim(filter_table_name.Text) > "" Then
            strWHERE = strWHERE & " table_name like '%" & filter_table_name.Text & "%' AND"
        End If
        
        If strWHERE > "" Then
            strWHERE = " where " & Mid(strWHERE, 1, Len(strWHERE) - 4)
        End If
        
    End Sub
    
    Sub gridMaster_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles gridMaster.PageIndexChanging
        gridMaster.PageIndex = e.NewPageIndex
        Call Load_Master_Grid()
    End Sub
  
    Sub gridMaster_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridMaster.Sorting
  
        'default to ascending if new column is clicked   
  
        If hdn_gridMaster_Sort_Column.Value <> e.SortExpression Then
            hdn_gridMaster_Sort_Order.Value = "ASC"
        End If
  
        'toggle sort order if the same column is clicked   
  
        If hdn_gridMaster_Sort_Column.Value = e.SortExpression Then
            If hdn_gridMaster_Sort_Order.Value = "ASC" Then
                hdn_gridMaster_Sort_Order.Value = "DESC"
            Else
                hdn_gridMaster_Sort_Order.Value = "ASC"
            End If
        End If
  
        hdn_gridMaster_Sort_Column.Value = e.SortExpression
  
        gridMaster.PageIndex = 0
        Call Load_Master_Grid()
  
    End Sub
 
    Sub btnApplyFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Call Load_Master_Grid()
    End Sub
    
   
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Human Resources</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript"  type="text/javascript" src="javascripts/CommonClientSideFunctions.js"></script>
<script language="JavaScript"  type="text/javascript">
 function Popup_Edit_Window(in_PK)
 {
    var url ="Detail_Page.aspx?PK=" + in_PK; 
    var height = 500;
    var width = 800;
    var top=100;
    var left=50;
  
    var features='height='+ height +',width='+ width +',top='+ top +',left='+ left+",scrollbars=yes,status=yes";
    popupWindow1=window.open(url,'detailwindow',features);
    popupWindow1.focus();
 }
 </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <asp:HiddenField ID="hdn_gridMaster_Sort_Order" runat="server" />
    <asp:HiddenField ID="hdn_gridMaster_Sort_Column" runat="server" />
 
     <!-- Filter Box -->
    <br/>
    <table align="center">
    <tr>
    <td>Table Type</td>
    <td><asp:DropDownList ID="filter_table_type"  AppendDataBoundItems="True" Width="200" runat="server">
        </asp:DropDownList>
   </td>
    <td>Table Name</td>
    <td> <asp:TextBox ID="filter_table_name" runat="server"></asp:TextBox>
    </td>
    <td><asp:Button ID="btnApplyFilter" runat="server" Text="Apply Filter" OnClick="btnApplyFilter_Click" />
    </td>
    
    </tr>
    </table>
        
    <br/>
   
    <!-- Master Grid -->
    <table align="center">
    <tr>
    <td>
    <div align="left">
    <asp:GridView ID="gridMaster" CssClass="gridMaster"  Width="900" runat="server" AllowSorting="true" AllowPaging="true"  EmptyDataText="There are no data records to display."  >
    <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
    </asp:GridView>
    </div>
    </td>
    </tr>
    </table>
    </form>
</body>
</html>
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: crickpaolo
Solution Provided By: CmdoProg2
Participating Experts: 1
Solution Grade: A
Views: 244
Translate:
Loading Advertisement...
02.20.2008 at 02:49PM PST, ID: 20942885

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.21.2008 at 09:10AM PST, ID: 20949676

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628