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
Printable View
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
Add TemplateField into GridView(I forget the name in DataGrid), and then add whatever control as you want into ItemTemplete.
Yes
or to go more in detail :
<datagrid....
<asp:TemplateColumn HeaderText="company">
<ItemTemplate>
<asp:DropDownList ID="ddlcompany" runat="server" DataValueField="companycode" DataTextField="companyname"
DataSource='<%# GetACompany() %>'> </asp:DropDownList>
</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
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
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 :
<asp:datagrid 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