Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.


Hi all
 I have a questions that looks hard / complex to me, and i know you can help me in this.
Q

I have row in a Gridview and i have an edit option to it.
I press the edit button, to edit the values in that row and update data all the way back to the database.
Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.)
}
I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in a gridview.
Kindly help me out on this 1...wiating for your replies.
Regards,
Bassam
0
Bassam
4/26/2007 7:52:31 PM
📁 asp.net.presentation-controls
📃 72751 articles.
⭐ 3 followers.

💬 1 Replies
👁️‍🗨️ 3307 Views



Hi there,
thats easy my friend:
Just replace the Textboxes inside the EditItemTemplate of the GridView with the controls you need and bind them to the columns from the sqldatasource/objectdatasource.
Here is an example:
  <Columns>
                                        <asp:TemplateField ShowHeader="False">
                                            <EditItemTemplate>
                                                <asp:Button ID="Update" runat="server" CausesValidation="True" CommandName="Update"
                                                    Text="Update" Width="55" /><asp:Button ID="Cancel" runat="server" CausesValidation="False"
                                                        CommandName="Cancel" Text="Cancel" Width="55" OnClientClick="return confirm('Cancel updates?');" />
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:Button ID="Add" runat="server" Enabled="false" CommandName="Add" OnClick="btnAdd_Click"
                                                    Text="Add" Width="55" /><asp:Button ID="Cancel" runat="server" CommandName="Cancel"
                                                        Text="Cancel" Width="55" />
                                            </FooterTemplate>
                                            <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                            <ItemTemplate>
                                                <asp:Button ID="Select" runat="server" CausesValidation="False" CommandName="Select"
                                                    Text="Select" Width="55" /><asp:Button ID="Edit" runat="server" CausesValidation="False"
                                                        CommandName="Edit" Text="Edit" Visible='<% #ShowBasedOnRole() %>' Width="55" /><asp:Button
                                                            ID="Delete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"
                                                            Visible='<% #ShowBasedOnRoleProduction() %>' OnClientClick="return confirm('Are you sure you want to delete this budget and all related data?');"
                                                            Width="55" /><asp:Button ID="Check" runat="server" CommandArgument='<%# Bind("ROWID") %>'
                                                                CommandName="Check" Text="Check" Visible='<% #ShowBasedOnRole() %>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ROWID" Visible="False">
                                            <EditItemTemplate>
                                                <asp:Label ID="editrowid" runat="server" Text='<%# Eval("ROWID") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="lblrow" runat="server" Text='<%# Bind("ROWID") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Fiscal Year" SortExpression="FISCALYEAR">
                                            <EditItemTemplate>
                                                <asp:Label ID="TextBox1" runat="server" Text='<%# Bind("FISCALYEAR") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="dropfiscalyear" runat="server">
                                                    <asp:ListItem Value="2007">2007</asp:ListItem>
                                                    <asp:ListItem Value="2008">2008</asp:ListItem>
                                                    <asp:ListItem Value="2009">2009</asp:ListItem>
                                                    <asp:ListItem Value="2010">2010</asp:ListItem>
                                                    <asp:ListItem Value="2011">2011</asp:ListItem>
                                                    <asp:ListItem Value="2012">2012</asp:ListItem>
                                                    <asp:ListItem Value="2013">2013</asp:ListItem>
                                                    <asp:ListItem Value="2014">2014</asp:ListItem>
                                                    <asp:ListItem Value="2015">2015</asp:ListItem>
                                                </asp:DropDownList>
                                            </FooterTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="lblfiscalyear" runat="server" Text='<%# Bind("FISCALYEAR") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Production" SortExpression="PRODUCTION">
                                            <EditItemTemplate>
                                                <asp:Label ID="TextBox2" runat="server" Text='<%# Bind("PRODUCTION") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:CheckBox ID="chkproduction" runat="server" AutoPostBack="true" OnCheckedChanged="chkproduction_CheckedChanged"
                                                    Visible='<% #ShowBasedOnRoleAndProduction() %>' />
                                            </FooterTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="lblproduction" runat="server" Text='<%# Production(DataBinder.Eval(Container.DataItem,"PRODUCTION","{0:c}").ToString()) %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Short Title" SortExpression="SHORTTITLE">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="short" runat="server" Font-Names="Arial" Text='<%# Bind("SHORTTITLE") %>'
                                                    TextMode="MultiLine"></asp:TextBox>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtshorttitle" runat="server" Font-Names="Arial" Rows="4" TextMode="MultiLine"></asp:TextBox>
                                            </FooterTemplate>
                                            <ItemStyle HorizontalAlign="Left" />
                                            <ItemTemplate>
                                                <asp:Label ID="lblshorttitle" runat="server" Text='<%# Bind("SHORTTITLE") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Long Title" SortExpression="LONGTITLE">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="long" runat="server" Font-Names="Arial" Text='<%# Bind("LONGTITLE") %>'
                                                    TextMode="MultiLine"></asp:TextBox>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtlongtitle" runat="server" Font-Names="Arial" Rows="4" TextMode="MultiLine"></asp:TextBox>
                                            </FooterTemplate>
                                            <ItemStyle HorizontalAlign="Left" Wrap="True" />
                                            <ItemTemplate>
                                                <asp:Label ID="lbllongtitle" runat="server" Text='<%# Bind("LONGTITLE") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Notes" SortExpression="NOTES">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="notes" runat="server" Font-Names="Arial" Text='<%# Bind("NOTES") %>'
                                                    TextMode="MultiLine"></asp:TextBox>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtnotes" runat="server" Font-Names="Arial" Rows="4" TextMode="MultiLine"></asp:TextBox>
                                            </FooterTemplate>
                                            <ItemStyle HorizontalAlign="Left" />
                                            <ItemTemplate>
                                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("NOTES") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="User" SortExpression="USERID">
                                            <EditItemTemplate>
                                                <asp:Label ID="TextBox6" runat="server" Text='<%# Eval("USERID") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:CheckBox ID="Initialize" runat="server" Text="Initialize" />
                                            </FooterTemplate>
                                            <ItemStyle HorizontalAlign="Left" Wrap="True" />
                                            <ItemTemplate>
                                                <asp:Label ID="Label7" runat="server" Text='<%# Bind("USERID") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Last Updated" SortExpression="LASTUPDATED">
                                            <EditItemTemplate>
                                                <asp:Label ID="TextBox7" runat="server" Text='<%# Eval("LASTUPDATED", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label8" runat="server" Text='<%# Eval("LASTUPDATED", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
thanks,
Murthy here 

Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Murthy
4/27/2007 1:21:08 AM
Reply: