command button in datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalini166
    New Member
    • Apr 2008
    • 70

    command button in datagrid

    I place command button in datagrid.

    When i click one button in the column.Another form or other datagrid will open.

    i don't how to make click event for column in the datagrid.please help me.


    pls help me.
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    You should take button control on the grid as follows :

    Code:
    <ItemTemplate>
    <asp:Button id="Button1" runat= Server" CommandName ="OpenForm"></asp:Button>
    </ItemTemplate>
    Now in DataGrid1_ItemC ommand() procedure write the code below . When you will click on button in any row , it will be handled by the following code:

    Code:
    Private Sub datagrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles datagrid1.ItemCommand
    
               If(e.CommandName = "OpenForm") Then
                 ''Perform some action
                   ..............................
               End If
    End Sub

    Originally posted by shalini166
    I place command button in datagrid.

    When i click one button in the column.Another form or other datagrid will open.

    i don't how to make click event for column in the datagrid.please help me.


    pls help me.

    Comment

    • shalini166
      New Member
      • Apr 2008
      • 70

      #3
      Originally posted by shweta123
      Hi,

      You should take button control on the grid as follows :

      Code:
      <ItemTemplate>
      <asp:Button id="Button1" runat= Server" CommandName ="OpenForm"></asp:Button>
      </ItemTemplate>
      Now in DataGrid1_ItemC ommand() procedure write the code below . When you will click on button in any row , it will be handled by the following code:

      Code:
      Private Sub datagrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles datagrid1.ItemCommand
      
                 If(e.CommandName = "OpenForm") Then
                   ''Perform some action
                     ..............................
                 End If
      End Sub
















      Hi swheta

      In that datagrid i have 6 to 7 rows.All of them contain view(button).wh en i click view in the 4th or 5th row then that complete row will displayed in another row,
      I want to know which view button is clicked and that particular row only retrieved.

      pls help me as soon as possible.

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        In DataGrid1_ItemC ommand procedure e.Item.ItemInde x will give you row index for which button(View) is clicked. ItemIndex starts with zero. So if you click on button in 5th row ItemIndex will be 4.

        Originally posted by shalini166
        Hi swheta

        In that datagrid i have 6 to 7 rows.All of them contain view(button).wh en i click view in the 4th or 5th row then that complete row will displayed in another row,
        I want to know which view button is clicked and that particular row only retrieved.

        pls help me as soon as possible.

        Comment

        • shalini166
          New Member
          • Apr 2008
          • 70

          #5
          Hi

          My coding is below.

          public void datagrid5_ItemC ommand(Object Source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
          {

          CheckBox cb5;

          foreach (DataGridItem dgItem5 in DataGrid5.Items )
          {
          cb5 = (CheckBox)dgIte m5.FindControl( "checkb5");
          if (cb5.Checked == true)
          {
          DataGridItem container5 = (DataGridItem)c b5.NamingContai ner;
          if(e.CommandNam e == "ViewButton ")
          {

          strcomp = container5.Cell s[2].Text;
          BindDataspare() ;

          }

          }
          }
          }

          public void BindDataspare()
          {
          string js = "select j.jacode,c.comp onentcode,c.com ponentname from component c,jobschedule j where c.componentname = '" + strcomp + "' and c.componentname =j.cname ";
          SqlDataAdapter ad = new SqlDataAdapter( js, sqlcon);
          DataSet ds = new DataSet();
          ad.Fill(ds, "job");
          DataGrid6.DataS ource = ds;
          DataGrid6.DataB ind();

          }

          Here The second datagrid display all the field from jobschedule.i need only one from jobschedule base on selection from first datagrid.

          pls help swetha.

          Comment

          Working...