Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Multiple Events for GridView?Multiple Events for GridView?
Previous
 
Next
New Post
7/18/2007 3:17 PM
 

Hello,

Have a question that I am sure has a simple answer. That's why I'm here!
Basically I have a gridview and a few buttons within module.
I am currently able to view data within gridview from sql database.

Here is the code I am using for viewing existing data.
Sample Code:


Private
Sub ShowData(ByVal SearchString As String)
Dim mySqlString As New StringBuilder()
mySqlString.Append(
"SELECT FirstName, LastName, Address, City, State ")
mySqlString.Append(
"FROM {databaseOwner}{objectQualifier} UserInformation ")
mySqlString.Append(
"WHERE LastName like '%' + @SearchString + '%' ")
mySqlString.Append(
"ORDER BY FirstName")
Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)
myParam.Value = SearchString
Me.GridView2.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)Me.GridView2.DataBind()
End 
Sub


Presently the data is being sorted by FirstName.
I would like to have a dropdown, checkboxes or buttons that give a few options of how to sort.
So whether dropdown, checkbox or buttons, options would be sort by Address, City, State, etc.

I am familiar with vb coding and have tried rigging events for each individual button, but it seems that more than one
DataSource and Params make module error out.

I actually could see this working best as an if / then statement within same event, but am not sure how the
code would break up for the different options. The only other thing I could think of, would be to rig each option, whether
dropdown, checkbox or buttons to operate accordingly when clicked.
But cannot find code for button1.clicked = true....or something to that effect. 
(as in: to be placed within code above, not referring to Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
I am actually awaiting a response on this concern from within another post.

Here's what I need to know:

1. Can I run multiple events using samplecode, with different parameters for each?
    Meaning:  In each Protected Sub btn_Click (of each button option), using the samplecode, but with different sort orders.
                  If so, what tags must be changed in samplecode?  (ex: Dim
mySqlString  changed to Dim mySqlString2)

2. Is it better to create multiple events like asked in Question #1, or to create an if / then statement that does this?

3. Is there code within asp.net for the value of a button, checkbox, dropdown being clicked outside of it's own sub?

4. What is your suggested code for this fix?




-Machina12

 
New Post
7/18/2007 4:55 PM
 



Well it's pretty rewarding when you can answer your own post.
I kept digging and found the answers for my questions.

Question 1:   Yes, but some event values must be changed to be unique.

Question 2:   Yes, this was the best route anyway. Rather than having multiple buttons and so much going on.
                        A custom sort function (other than usual column sorts) should be simple coding.
                        So there was no need for values within each button box, when I could run an If statement.
                        Found it best to input using:  If, IfThen, and Else Statements.
                        Each within the same sub, so no need for renaming values, and changes in actions accordingly.

Question 3:  Still awaiting an answer on this from other post. If you know, please respond.
                       Looking for ability to have code within buton A's sub click Button B. Basically telling Button A's sub to put state of
                       Button B as clicked.  Then the sub for Button B should execute.  Not sure if this exists, or a logic fantasy?

Question 4:  I have no clue what you are thinking, becuase I ended up answering my own post.
                       Knowledge is power. Even if you find the answers yourself.
                       Never stop digging.


-Machina12

 
New Post
7/18/2007 5:19 PM
 

Below I have two template columns in one of my GridViews, one deletes a record and one redirects to another page. The concept is the same. You give it a command name and in the RowCommand function, if the commandname =  "whatever" do this

<asp:TemplateField ItemStyle-BorderStyle="None" HeaderStyle-BorderStyle="none">
                            <ItemTemplate>
                                <asp:LinkButton ID="cmdDeleteJob" runat="server"  CommandName="CancelJob" Text="Delete" CssClass="CommandButton" CommandArgument='<%# Bind("RecordId") %>' OnClientClick="return confirm('Are you sure you want to delete this item?');"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-BorderStyle="None" HeaderStyle-BorderStyle="none">
                            <ItemTemplate>
                                <asp:LinkButton ID="cmdDownload" runat="server" CommandName="Download" Text="Download" CssClass="CommandButton" CommandArgument='<%# Bind("RecordName") %>'></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                    </Columns>

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
            If e.CommandName = "CancelJob" Then
                'run the delete code here
                Dim jobNo As Integer = CType(e.CommandArgument, Integer)

                Dim ctl as new CustomModuleController
                ctrl.DeleteReportQueue(jobNo)
                GridView1.databind()
            End If

            If e.CommandName = "Download" Then
                Response.Redirect(appPath + "/ReportFolder/" + e.CommandArgument)
            End If

        End Sub

Check out these tutorials for more information.

http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

 
New Post
7/18/2007 5:27 PM
 

Machina12,  

As an alternative, you may want to consider the free module SQLGridSelectedView as this module does provide many different filtering options similar to what you are attempting in code. You can find it here at www.tressleworks.ca

Enjoy, Paul.

 

 
New Post
7/19/2007 12:05 PM
 

Machina12:

Regarding Q3, if you have common code that you want to execute from multiple controls (or their events), why not break that code out into a separate class or function that you can easily (and very cleanly) invoke from anywhere?

Carlos

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Multiple Events for GridView?Multiple Events for GridView?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out