CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Posts
    10

    Datagrid with DropdownMenu and Button

    hi
    i hv a Datagrid which hv a dropdownmenu and a button in each row
    i want to populate the dropdown menu inside the Datagrid..
    i want to add Upload button inside the datagrid..
    any idea pls
    waiting for ur valuable reply
    veeresh

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: Datagrid with DropdownMenu and Button

    Add TemplateField into GridView(I forget the name in DataGrid), and then add whatever control as you want into ItemTemplete.

  3. #3
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    17

    Re: Datagrid with DropdownMenu and Button

    Yes

    or to go more in detail :
    <datagrid....

    <asp:TemplateColumn HeaderText="company">

    <ItemTemplate>
    <aspropDownList ID="ddlcompany" runat="server" DataValueField="companycode" DataTextField="companyname"
    DataSource='<%# GetACompany() %>'> </aspropDownList>
    </ItemTemplate>

    </asp:TemplateColumn>


    ... same itemtemplate voor button ..
    <asp:button id="cmdUpload" command="Upload" runat="server">....
    ...

    </datagrid>

    then in your codebehind build a dataset in the function getcompany en return it.


    Function Getcompany() As Data.DataSet
    Try
    Dim dscompany As New Data.DataSet

    .... get data from database and fill dataset

    Return dscomlpany
    Catch ex As Exception
    Return Nothing
    End Try
    End Function

    that should work for you...

    greetz
    Geert

  4. #4
    Join Date
    Jun 2006
    Posts
    10

    Re: Datagrid with DropdownMenu and Button

    hi

    thankyou.. i hv populated dropdown list..

    now i want to add a button to the datagrid..

    here is the code. i hv used ..


    <asp:TemplateColumn HeaderText="File Name">

    <ItemStyle Wrap="False" />

    <HeaderStyle CssClass="orderIdItem" Wrap="False" />

    <ItemTemplate>

    <asp:ImageButton ID=Upload runat=server />

    </ItemTemplate >

    </asp:TemplateColumn>
    In the Code Behind..

    ImageButton

    img = (ImageButton)item.Cells[2].Controls[1];


    //ImageButton img = new ImageButton();
    uploadurl =

    "~/Skins/" + skinname + "/Uploadnormal.gif";
    img.ImageUrl=uploadurl;

    img.Attributes.Add(

    "onmouseover", "this.src='Skins/" + skinname + "/Uploadhover.gif';");
    img.Attributes.Add(

    "onmouseout", "this.src='Skins/" + skinname + "/Uploadnormal.gif';");
    item.Cells[3].Controls.Add(img);



    Now i add the Button control to the datagrid..

    pls tell me .. how can i handle the click event of the button inside the DataGrid??

    waiting for ur valuable reply

    thankyou

  5. #5
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    17

    Re: Datagrid with DropdownMenu and Button

    Hi,

    In your datagrid you can add several commands to react to your actions.

    if you want for example add a row using that button :

    In your datagrid you add the following :
    <aspatagrid runat="server".... onItemcommand="Add_Item" ... >

    your button is correct, but just add the item "Commandname":

    <asp:TemplateColumn HeaderText="File Name">
    <ItemStyle Wrap="False" />
    <HeaderStyle CssClass="orderIdItem" Wrap="False" />
    <ItemTemplate>
    <asp:ImageButton ID=Upload CommandName="InsertItem" runat=server />
    </ItemTemplate >
    </asp:TemplateColumn>


    Codebehind :
    Sub AddItem(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    If e.CommandName = "InsertItem" Then

    'DO What you want
    'To get your dropdownlistitem
    Dim Lstdropdown As DropDownList = _
    e.Item.FindControl("ddlname")

    .... use its value
    dim iListID as integer
    iListID = LstAfdeling.SelectedItem.Value

    ....

    end if
    end sub

    Hope it works out
    greetz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured