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. Follow

1 Replies
2343 Views

Similar Articles

[PageSpeed] 16

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><br />
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtshorttitle" runat="server" Font-Names="Arial" Rows="4" TextMode="MultiLine"></asp:TextBox><br />
                                            </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><br />
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtlongtitle" runat="server" Font-Names="Arial" Rows="4" TextMode="MultiLine"></asp:TextBox><br />
                                            </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:

Web resources about - Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control. - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

England 'lost control' of Sam Burgess signing, says Bath coach Mike Ford
Bath head coach Mike Ford has reversed his support of Sam Burgess by stating that he should never have made the England 2015 World Cup squad. ...

Apple again controls holiday sales, accounting for 49% of activations as phablets dominate
... For more information about iOS Devices , Apple , and iPhone continue reading at 9to5Mac . What do you think? Discuss "Apple again controls ...

LG’s Amazon Echo-like device controls smart home devices and plays music
... a new device that looks somewhat familiar. The company announced its SmartThinq Hub today, a smart home hub with an LCD display that can control ...

Disable Windows 10 upgrade prompts with GWX Control Panel 1.7
... then the constant "Get Windows 10!" alerts are probably getting annoying. Fortunately you can disable them in seconds with the free GWX Control ...

Bloomberg Business: Executive Gun Control Coming ‘Soon After New Year’s Day’
Bloomberg Business: Executive Action Expanding Gun Control 'Soon After New Year's Day'

pics: Royal Trux @ Webster Hall w/ IUD, Blues Control & Lexie Mountain
photos by P Squared Royal Trux @ Webster Hall, 12/19/2015 "It just seemed pretty natural," Herrema said. "I guess when you know somebody that ...

Do parents give their kids too much control?
Family physician Dr. Leonard Sax explains how some problems unique to American culture are leading to a shift in authority

State Lawmakers Prep Gun Control Policies For 2016
State Lawmakers Prep Gun Control Policies For 2016

Smash glitch lets you control eight characters at once
... around in the game seeing what corners and cracks they can find hidden in its depths. If you've ever for some weird reason wanted to control ...

Resources last updated: 12/31/2015 1:33:48 PM