iftech
asked on
programmatically create gridview
Hi,
I would like to duplicate the look and functionality of the ASP.Net gridview below programmatically. Can you tell me how please?
I would like to duplicate the look and functionality of the ASP.Net gridview below programmatically. Can you tell me how please?
<asp:GridView ID="gvDocs" runat="server"
Visible="true"
AllowSorting="true"
AllowPaging="true"
PagerSettings-Mode="NumericFirstLast"
PageSize="20"
OnPageIndexChanging="gvDocs_PageIndexChanging"
OnSorting="gvDocs_Sorting"
AutoGenerateColumns="False"
OnRowCancelingEdit="gvDocs_RowCancelingEdit"
OnRowEditing="gvDocs_RowEditing"
OnRowUpdating="gvDocs_RowUpdating"
OnRowDeleting="gvDocs_RowDeleting"
OnRowDataBound="gvDocs_RowDataBound"
ShowFooter="False"
DataKeyNames="PatientDocID, ProfessionalID"
CellPadding="4"
GridLines="None"
Width="100%">
<Columns>
<asp:TemplateField HeaderText="Quadrant" SortExpression="Quadrant" HeaderStyle-Width="70px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<EditItemTemplate>
<asp:Label ID="lblQuadrant" runat="server" Text='<%# Bind("Quadrant") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblQuadrant" runat="server" Text='<%# Bind("Quadrant") %>' />
</ItemTemplate>
<ItemStyle CssClass="gridData" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Document" SortExpression="FileName" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<EditItemTemplate>
<asp:Label ID="lblEditFileName" runat="server" Text='<%# Bind("FileName") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="hyprGridDocLink" runat="server" Text='<%# Eval("filename") %>' NavigateUrl='<%# "~/documents/" + Eval("folder") +"/" + Eval("filename") %>' Target="_blank" />
</ItemTemplate>
<ItemStyle CssClass="gridData" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Uploaded By" SortExpression="UploadedBy" ItemStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<EditItemTemplate>
<asp:Label ID="lblEditUploadedBy" runat="server" Text='<%# Bind("UploadedBy") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblUploadedBy" runat="server" Text='<%# Bind("UploadedBy") %>' />
</ItemTemplate>
<ItemStyle CssClass="gridData" />
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right">
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" runat="server" CausesValidation="true" ValidationGroup="vgEditDoc"
CommandName="Update" ImageUrl="~/images/sub/saveAlt.gif"/><asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/images/sub/cancelAlt.gif"/>
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" runat="server" CausesValidation="false"
CommandName="Edit" ImageUrl="~/images/sub/edit.gif"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description" ItemStyle-Width="220px" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" >
<EditItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" Width="220px" Text='<%# Bind("Description") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>' />
</ItemTemplate>
<ItemStyle CssClass="gridData" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="UploadDate" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<EditItemTemplate>
<asp:Label ID="lblEditDate" runat="server" Text='<%# string.Format("{0:MMM dd, yyyy}", Eval("UploadDate")) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# string.Format("{0:MMM dd, yyyy}", Eval("UploadDate")) %>' />
</ItemTemplate>
<ItemStyle CssClass="gridData" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Remove" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnRemove" runat="server" CausesValidation="false"
CommandName="Delete" ImageUrl="~/images/sub/delete.gif"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#595959 " Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" HorizontalAlign="Center" />
<EditRowStyle BackColor="#999999" VerticalAlign="Top" HorizontalAlign="Center" />
<AlternatingRowStyle CssClass="altRow" />
<RowStyle CssClass="defaultRow" />
<HeaderStyle CssClass="title" />
</asp:GridView>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One simple trick I follow while doing big projects is to break it into simple pieces. You can try that on your gridview. Have a basic gridview, make sure it renders fine. Then add the edit part for the gridview and make sure it works correctly.. and so on.
Here are some links that'll help you with an editable gridview.
http://www.codeproject.com/KB/webforms/Editable_GridView.aspx
http://msdn.microsoft.com/en-us/library/ms972948.aspx
Arun
Here are some links that'll help you with an editable gridview.
http://www.codeproject.com/KB/webforms/Editable_GridView.aspx
http://msdn.microsoft.com/en-us/library/ms972948.aspx
Arun
ASKER
I see your point. However the gridview does render correctly. Just some functionality isn't working. the events are firing but the databind seems to do nothing.
thanks for your help
thanks for your help
Din't the links help you in any way?
Arun
Arun
ASKER
Well they did... kind of, the last gridview in the repeater list works as it should but the others don't.
ASKER
I got it all to work. thanks for your help. Although I figured most of it out myself but I will award you the points.
ASKER
I looked over the links and decided not to do it at run time. My issue is:
I have a repeater that with a datatable datasource. The repeater has 2 items.
1- is a date field label for the date documents were uploaded.
2- the other is a gridview contain information about the uploaded file. eg. link to file, name, discription.
some of the fields in the gridview must be editable.
The gridview won't go into edit mode and won't refresh after a file has been removed. I have included the asp.net markup and my event handlers. Can you see if I'm
missing anything.
Thanks alot.
Open in new window