Button Column Select.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rcoco

    Button Column Select.

    Hi all,
    I have a datagrid with Button column select in form of hyperlink. On
    the same page, I have another datagrid that insert data and one
    column(Name) has Names of a user that is inserting data(using windows
    authentication) .
    Now this is how it's supposed to work: When any user want to see data
    about a particular user it's a matter of selecting his name and the
    data Writen by the selected user should be the only ones to be shown.
    I got some examples on Google but they all seem not to be working.
    When a user is selected the page remains the same data is not
    selected. How would can I solve this problem?
    My code looks like this:
    HTML part:
    <Columns>
    <asp:ButtonColu mn HeaderText="Ope rations"
    DataTextField=" TeamOperation" ButtonType="Lin kButton"></
    asp:ButtonColum n>
    </Columns>
    and code behind:
    private void dgoperation_Ite mCommand(object source,
    System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    {
    SqlCommand myCommand=new SqlCommand();
    myCommand.Conne ction=con;
    myCommand.Comma ndText="select * from dbo.DashBoard where Name =
    @Billing";
    myCommand.Param eters.Add(new SqlParameter("@ Billing",SqlDbT ype.VarChar,
    50));
    myCommand.Param eters["@Billing"].Value= dgbilling;
    SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
    DataSet ds = new DataSet();
    myAdapter.Fill( ds);
    dgis.DataSource =ds;
    dgis.EditItemIn dex = -1;
    dgis.DataBind() ;
    }

    dgis: this is the datagrid that where user inserts data.
    dgbilling: this is the datagrid with the name list.
    Thanks.

  • rcoco

    #2
    Re: Button Column Select.

    I have corrected my statement and this time I'm getting this error:
    "Object reference not set to an instance of an object."
    And the error source:
    Line 219: myCommand.Comma ndText="select * from dbo.DashBoard where
    Name Like @Billing";
    Line 220: myCommand.Param eters.Add(new
    SqlParameter("@ Billing",SqlDbT ype.VarChar,50) );
    Line 221: myCommand.Param eters["@Billing"].Value= bc.Text;
    Line 222: SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
    Line 223: DataSet ds = new DataSet();
    This is my code:
    <Columns>
    <asp:ButtonColu mn HeaderText="Ope rations"
    DataTextField=" TeamOperation" ButtonType="Lin kButton"
    CommandName="Se lect"></asp:ButtonColum n>
    </Columns>
    My code behind:
    private void dgoperation_Ite mCommand(object source,
    System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    {
    System.Web.UI.W ebControls.Link Button bc=new
    System.Web.UI.W ebControls.Link Button();
    bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamBilling");
    SqlCommand myCommand=new SqlCommand();
    myCommand.Conne ction=con;
    myCommand.Comma ndText="select * from dbo.DashBoard where Name Like
    @Billing";
    myCommand.Param eters.Add(new SqlParameter("@ Billing",SqlDbT ype.VarChar,
    50));
    myCommand.Param eters["@Billing"].Value= bc.Text;
    SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
    DataSet ds = new DataSet();
    myAdapter.Fill( ds);
    dgis.DataSource =ds;
    dgis.EditItemIn dex = -1;
    dgis.DataBind() ;
    }
    How can I solve this?
    Thanks

    Comment

    • Alexey Smirnov

      #3
      Re: Button Column Select.

      On May 18, 3:14 pm, rcoco <nclau...@yahoo .cawrote:
      myCommand.Conne ction=con;
      What is 'con'? Did you created a SqlConnection reference already?

      For example,

      SqlConnection con = new SqlConnection(" my_connection_s tring");

      Comment

      • rcoco

        #4
        Re: Button Column Select.

        Hi Alexey,
        con is:
        SqlConnection con = new SqlConnection(" user
        id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ard;");
        Thanks

        Comment

        • Alexey Smirnov

          #5
          Re: Button Column Select.

          On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
          Hi Alexey,
          con is:
          SqlConnection con = new SqlConnection(" user
          id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ­ard;");
          Thanks
          Well, but where do you create it?

          The code above looks correct and I can only guess that possibly your
          connection object is not a global available reference.

          Is it a code-behind class? If yes, did you compiled it?

          Comment

          • rcoco

            #6
            Re: Button Column Select.

            On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
            On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
            >
            Hi Alexey,
            con is:
            SqlConnection con = new SqlConnection(" user
            id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ­­ard;");
            Thanks
            >
            Well, but where do you create it?
            >
            The code above looks correct and I can only guess that possibly your
            connection object is not a global available reference.
            >
            Is it a code-behind class? If yes, did you compiled it?
            Yes it's a code behind.
            I think the problem was
            System.Web.UI.W ebControls.Link Button bc=new
            System.Web.UI.W ebControls.Link Button();
            bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB­
            illing");
            So I have now tryed Writing the code like this.
            System.Web.UI.W ebControls.Butt onColumn bc=new
            System.Web.UI.W ebControls.Butt onColumn();
            bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S elect") ;
            SqlCommand myCommand=new SqlCommand();
            myCommand.Conne ction=con;
            myCommand.Comma ndText="select * from dbo.DashBoard where Name =
            @operation";
            myCommand.Param eters.Add(new
            SqlParameter("@ operation",SqlD bType.VarChar,5 0));
            myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
            con.Open();
            myCommand.Execu teNonQuery();
            con.Close();
            dgis.EditItemIn dex=-1;
            Fill();
            Bind();
            But when compiling I get this error
            C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
            type 'System.Web.UI. Control' to
            'System.Web.UI. WebControls.But tonColumn'
            I'm not sure if I'm on the right track! What do you think?
            Thank you very much.

            Comment

            • Alexey Smirnov

              #7
              Re: Button Column Select.

              On May 21, 11:41 am, rcoco <nclau...@yahoo .cawrote:
              On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
              >
              On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
              >
              Hi Alexey,
              con is:
              SqlConnection con = new SqlConnection(" user
              id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ­­­ard;");
              Thanks
              >
              Well, but where do you create it?
              >
              The code above looks correct and I can only guess that possibly your
              connection object is not a global available reference.
              >
              Is it a code-behind class? If yes, did you compiled it?
              >
              Yes it's a code behind.
              I think the problem was
              System.Web.UI.W ebControls.Link Button bc=new
              System.Web.UI.W ebControls.Link Button();
              bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB­­
              illing");
              So I have now tryed Writing the code like this.
              System.Web.UI.W ebControls.Butt onColumn bc=new
              System.Web.UI.W ebControls.Butt onColumn();
              bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S el­ect") ;
              SqlCommand myCommand=new SqlCommand();
              myCommand.Conne ction=con;
              myCommand.Comma ndText="select * from dbo.DashBoard where Name =
              @operation";
              myCommand.Param eters.Add(new
              SqlParameter("@ operation",SqlD bType.VarChar,5 0));
              myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
              con.Open();
              myCommand.Execu teNonQuery();
              con.Close();
              dgis.EditItemIn dex=-1;
              Fill();
              Bind();
              But when compiling I get this error
              C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
              type 'System.Web.UI. Control' to
              'System.Web.UI. WebControls.But tonColumn'
              I'm not sure if I'm on the right track! What do you think?
              Thank you very much.
              First of all, remember, the "code behind" classes must be compiled
              into an assembly, which is placed by VS.NET in the \bin directory.
              When you get an error during compilation, you cannot run the actual
              code, because your classes simply did not compiled and a DLL in the
              \bin directory was not updated.

              Regarding your LinkButton.

              I'm not very well understood why you used this

              <asp:ButtonColu mn DataTextField=" TeamOperation" ...

              Maybe you can explain, what you did supposed to get there

              I suppose, you wanted to have this

              <asp:ButtonColu mn CommandName="Te amOperation"... .

              which can be simply accessed as

              e.CommandName

              in your dgoperation_Ite mCommand() function

              e.g.

              myCommand.Param eters["@operation "].Value= e.CommandName;

              without any extra code.

              However, in this case I don't see the sense of the

              "select * from dbo.DashBoard where Name = @operation";

              Comment

              • rcoco

                #8
                Re: Button Column Select.

                On May 21, 1:21 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                On May 21, 11:41 am, rcoco <nclau...@yahoo .cawrote:
                >
                >
                >
                >
                >
                On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                >
                On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
                >
                Hi Alexey,
                con is:
                SqlConnection con = new SqlConnection(" user
                id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ­­­­ard;");
                Thanks
                >
                Well, but where do you create it?
                >
                The code above looks correct and I can only guess that possibly your
                connection object is not a global available reference.
                >
                Is it a code-behind class? If yes, did you compiled it?
                >
                Yes it's a code behind.
                I think the problem was
                System.Web.UI.W ebControls.Link Button bc=new
                System.Web.UI.W ebControls.Link Button();
                bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB­­­
                illing");
                So I have now tryed Writing the code like this.
                System.Web.UI.W ebControls.Butt onColumn bc=new
                System.Web.UI.W ebControls.Butt onColumn();
                bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S el­­ect") ;
                SqlCommand myCommand=new SqlCommand();
                myCommand.Conne ction=con;
                myCommand.Comma ndText="select * from dbo.DashBoard where Name =
                @operation";
                myCommand.Param eters.Add(new
                SqlParameter("@ operation",SqlD bType.VarChar,5 0));
                myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
                con.Open();
                myCommand.Execu teNonQuery();
                con.Close();
                dgis.EditItemIn dex=-1;
                Fill();
                Bind();
                But when compiling I get this error
                C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
                type 'System.Web.UI. Control' to
                'System.Web.UI. WebControls.But tonColumn'
                I'm not sure if I'm on the right track! What do you think?
                Thank you very much.
                >
                First of all, remember, the "code behind" classes must be compiled
                into an assembly, which is placed by VS.NET in the \bin directory.
                When you get an error during compilation, you cannot run the actual
                code, because your classes simply did not compiled and a DLL in the
                \bin directory was not updated.
                >
                Regarding your LinkButton.
                >
                I'm not very well understood why you used this
                >
                <asp:ButtonColu mn DataTextField=" TeamOperation" ...
                >
                Maybe you can explain, what you did supposed to get there
                >
                I suppose, you wanted to have this
                >
                <asp:ButtonColu mn CommandName="Te amOperation"... .
                >
                which can be simply accessed as
                >
                e.CommandName
                >
                in your dgoperation_Ite mCommand() function
                >
                e.g.
                >
                myCommand.Param eters["@operation "].Value= e.CommandName;
                >
                without any extra code.
                >
                However, in this case I don't see the sense of the
                >
                "select * from dbo.DashBoard where Name = @operation";- Hide quoted text -
                >
                - Show quoted text -
                Thanks
                TeamOperation is a columns that has a list of users of the website. So
                by
                <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                names in datagrid "dgoperatio n".
                Thanks

                Comment

                • Alexey Smirnov

                  #9
                  Re: Button Column Select.

                  On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
                  Thanks
                  TeamOperation is a columns that has a list of users of the website. So
                  by
                  <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                  names in datagrid "dgoperatio n".
                  Thanks- Hide quoted text -
                  >
                  Ok, I think, I got it

                  Then try

                  myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;

                  assuming that "Operations " is the first column of the grid

                  Comment

                  • rcoco

                    #10
                    Re: Button Column Select.

                    On May 21, 3:43 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                    On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
                    >
                    Thanks
                    TeamOperation is a columns that has a list of users of the website. So
                    by
                    <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                    names in datagrid "dgoperatio n".
                    Thanks- Hide quoted text -
                    >
                    Ok, I think, I got it
                    >
                    Then try
                    >
                    myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                    >
                    assuming that "Operations " is the first column of the grid
                    Still does not select any data. All it does its like the page is just
                    being refreshed.
                    Thanks


                    Comment

                    • Alexey Smirnov

                      #11
                      Re: Button Column Select.

                      On May 21, 3:28 pm, rcoco <nclau...@yahoo .cawrote:
                      On May 21, 3:43 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                      >
                      >
                      >
                      >
                      >
                      On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
                      >
                      Thanks
                      TeamOperation is a columns that has a list of users of the website. So
                      by
                      <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                      names in datagrid "dgoperatio n".
                      Thanks- Hide quoted text -
                      >
                      Ok, I think, I got it
                      >
                      Then try
                      >
                      myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                      >
                      assuming that "Operations " is the first column of the grid
                      >
                      Still does not select any data. All it does its like the page is just
                      being refreshed.
                      Thanks- Hide quoted text -
                      >
                      - Show quoted text -
                      Well, at least there is no compilation error :-)

                      Try to see what you pass to the database: add a debug string, for
                      example

                      myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                      Response.Write "select * from dbo.DashBoard where Name = '" +
                      e.Item.Cells[0].Text + "'";

                      This would return a sql that you can execute against your database to
                      see if it is correct or not.

                      Comment

                      • rcoco

                        #12
                        Re: Button Column Select.

                        On May 21, 4:54 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                        On May 21, 3:28 pm, rcoco <nclau...@yahoo .cawrote:
                        >
                        >
                        >
                        >
                        >
                        On May 21, 3:43 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                        >
                        On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
                        >
                        Thanks
                        TeamOperation is a columns that has a list of users of the website. So
                        by
                        <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                        names in datagrid "dgoperatio n".
                        Thanks- Hide quoted text -
                        >
                        Ok, I think, I got it
                        >
                        Then try
                        >
                        myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                        >
                        assuming that "Operations " is the first column of the grid
                        >
                        Still does not select any data. All it does its like the page is just
                        being refreshed.
                        Thanks- Hide quoted text -
                        >
                        - Show quoted text -
                        >
                        Well, at least there is no compilation error :-)
                        >
                        Try to see what you pass to the database: add a debug string, for
                        example
                        >
                        myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                        Response.Write "select * from dbo.DashBoard where Name = '" +
                        e.Item.Cells[0].Text + "'";
                        >
                        This would return a sql that you can execute against your database to
                        see if it is correct or not.- Hide quoted text -
                        >
                        - Show quoted text -
                        I get select*from dbo.DashBoard where Name=
                        That's allit returns.
                        Thanks

                        Comment

                        • rcoco

                          #13
                          Re: Button Column Select.

                          On May 21, 4:54 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                          On May 21, 3:28 pm, rcoco <nclau...@yahoo .cawrote:
                          >
                          >
                          >
                          >
                          >
                          On May 21, 3:43 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
                          >
                          On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
                          >
                          Thanks
                          TeamOperation is a columns that has a list of users of the website. So
                          by
                          <asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
                          names in datagrid "dgoperatio n".
                          Thanks- Hide quoted text -
                          >
                          Ok, I think, I got it
                          >
                          Then try
                          >
                          myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                          >
                          assuming that "Operations " is the first column of the grid
                          >
                          Still does not select any data. All it does its like the page is just
                          being refreshed.
                          Thanks- Hide quoted text -
                          >
                          - Show quoted text -
                          >
                          Well, at least there is no compilation error :-)
                          >
                          Try to see what you pass to the database: add a debug string, for
                          example
                          >
                          myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                          Response.Write "select * from dbo.DashBoard where Name = '" +
                          e.Item.Cells[0].Text + "'";
                          >
                          This would return a sql that you can execute against your database to
                          see if it is correct or not.- Hide quoted text -
                          >
                          - Show quoted text -
                          It return select* from dbo.DashBoard where Name=
                          That is all it returns

                          Comment

                          • Alexey Smirnov

                            #14
                            Re: Button Column Select.

                            On May 21, 4:24 pm, rcoco <nclau...@yahoo .cawrote:
                            myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;
                            Response.Write "select * from dbo.DashBoard where Name = '" +
                            e.Item.Cells[0].Text + "'";
                            >
                            My mistake, sorry!

                            e.Item.Cells[0].Text will work for "normal" cells only, for the
                            ButtonColumn retrieving the text can be done with the reference to a
                            control and cast it to the LinkButton class

                            So, you @Billing value has to be as:

                            myCommand.Param eters["@Billing"].Value = ((LinkButton)
                            e.Item.Cells[0].Controls[0]).Text;

                            To be sure

                            Response.Write "select * from dbo.DashBoard where Name = '" +
                            ((LinkButton) e.Item.Cells[0].Controls[0]).Text + "'";

                            Comment

                            • Alexey Smirnov

                              #15
                              Re: Button Column Select.


                              "Alexey Smirnov" <alexey.smirnov @gmail.comwrote in message
                              news:1179773243 .348157.267380@ a26g2000pre.goo glegroups.com.. .
                              Response.Write "select * from dbo.DashBoard where Name = '" +
                              ((LinkButton) e.Item.Cells[0].Controls[0]).Text + "'";
                              >
                              Response.Write( ); should be with the parentheses


                              Comment

                              Working...