association of dropdownlist to a column while editing etc. from the code
AutoGenerateDeleteButton="True" / AutoGenerateEditButton="True". I like to
"Ken Cox [Microsoft MVP]" <BANSPAMkjopc@newsgroups.nospam> wrote in message
news:u9qgJVM3GHA.4364@TK2MSFTNGP06.phx.gbl...
> Hi Philjo,
>
> When you say "programmatically" do you mean adding the code based on an
> event? Otherwise, it is quite easy to include a dropdownlist that's bound
> to a field. See the code below.
>
> Likewise, what do you mean by "autogenerated"? You can uses images in
> template columns.
>
> Perhaps you could show us the code you have so far?
>
> Anyway, I've inserted some code below in case it helps.
>
> Ken
> Microsoft MVP [ASP.NET]
>
> <%@ Page Language="VB" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
> "
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> > <html xmlns="
http://www.w3.org/1999/xhtml" >
> <head id="hd" runat="server">
> <title>Dropdownlist in GridView - Ken Cox [MVP]</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:GridView
> id="gvProducts"
> DataSourceID="sqldsProducts"
> DataKeyNames="ProductId"
> AutoGenerateColumns="False"
> AutoGenerateEditButton="False"
> Runat="server">
> <Columns>
> <asp:templatefield showheader="False">
> <edititemtemplate>
> <asp:linkbutton id="LinkButton1" runat="server"
> causesvalidation="True" commandname="Update"
> text="Update"></asp:linkbutton>
> <asp:linkbutton id="LinkButton2" runat="server"
> causesvalidation="False" commandname="Cancel"
> text="Cancel"></asp:linkbutton>
> </edititemtemplate>
> <itemtemplate>
> <asp:imagebutton id="ImageEdit" runat="server"
> causesvalidation="False" commandname="Edit"
> imageurl="
http://eus.amrinteractive.com.au/EUS/config/Edit.JPG" />
> </itemtemplate>
> </asp:templatefield>
> <asp:TemplateField HeaderText="Product">
> <ItemTemplate>
> <%#Eval("ProductName")%>
> </ItemTemplate>
> <EditItemTemplate>
> <asp:textbox id="txtProductName"
> runat="server"
> text='<%# Bind("ProductName")%>'>
> </asp:textbox>
> <asp:requiredfieldvalidator
> id="rqdProductName"
> runat="server"
> controltovalidate="txtProductName"
> text="Please provide a product name.">
> </asp:requiredfieldvalidator>
> </EditItemTemplate>
> </asp:TemplateField>
> <asp:TemplateField HeaderText="Category">
> <ItemTemplate>
> <%#Eval("CategoryName")%>
> </ItemTemplate>
> <EditItemTemplate>
> <asp:DropDownList
> id="ddlCategory"
> DataSourceID="sqldsCategories"
> DataTextField="CategoryName"
> DataValueField="CategoryId"
> SelectedValue='<%#Bind("CategoryId")%>'
> Runat="server" />
> </EditItemTemplate>
> </asp:TemplateField>
>
> </Columns>
> </asp:GridView>
>
> <asp:sqldatasource id="sqldsProducts"
> runat="server"
> connectionstring=
> '<%$ ConnectionStrings:NorthwindConnectionString %>'
> selectcommand="SELECT Products.ProductId,
> Products.ProductName, Products.CategoryId,
> Categories.CategoryName
> FROM Products JOIN Categories
> ON Categories.CategoryId = Products.CategoryId"
> updatecommand="UPDATE Products SET ProductName=@ProductName,
> CategoryId=@CategoryId
> WHERE ProductId=@ProductId">
> </asp:sqldatasource>
>
> <asp:sqldatasource id="sqldsCategories"
> runat="server"
> connectionstring=
> '<%$ ConnectionStrings:NorthwindConnectionString %>'
> selectcommand="SELECT CategoryId,
> CategoryName FROM Categories">
> </asp:sqldatasource>
> </div>
> </form>
> </body>
> </html>
>
>
> "Philjo" <philip.joseph@uk.flovate.com> wrote in message
> news:ur9mWrK3GHA.3812@TK2MSFTNGP06.phx.gbl...
>> Folks,
>>
>>
>>
>> I am looking for some good samples which describe how we can
>> programmatically assign the following stuffs to a GridView control.
>>
>>
>>
>> 1. Association of a dropdownList with its data source to a grid column
>> using EditItemTemplate
>>
>> 2. Can I change the auto generated Edit, Update or Delete buttons in the
>> grid to an Image?
>>
>>
>>
>> Thanks in advance
>>
>> Philjo
>>
>
>