Footer Row failing to Insert into table via asp gridview - asp.net

I'm working with vb.net and have followed a tutorial to set up a gridview to update/delete/insert records into a table. I have a footer row that isn't working for me. when I click my insert button the textboxes from the footer do not do the insert. I think I am missing something fundamental that is causing this. May the page is posting back before the sub grabs the text from the textboxes? My understanding of it is pretty but I feel this could be the issue because I have two radio buttons that I use to switch between SQL data adapters because I want to be able to work with different tables. I have these set to postback="true". Could that be my issue?
SqlDataAdapter:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Server=SQLSERVER;Database=DB1;UID=user;PWD=password"
DeleteCommand="delete from AVZV_LoginRequestSales where id = #id"
SelectCommand="select * from AVZV_LoginRequestSales"
UpdateCommand="update AVZV_LoginRequestSales set name=#name, role = #role, supervisor = #supervisor, location = #location, trainingSdt = #trainingSdt, productionSdt = #productionSdt, terminatedDate = #terminatedDate, notes = #notes where id = #id">
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="firstname" />
<asp:Parameter Name="lastname" />
<asp:Parameter Name="role" />
<asp:Parameter Name="supervisor" />
<asp:Parameter Name="location" />
<asp:Parameter Name="trainingSdt" />
<asp:Parameter Name="productionSdt" />
<asp:Parameter Name="terminatedDate" />
<asp:Parameter Name="notes" />
</UpdateParameters>
</asp:SqlDataSource>
Datagrid:
<asp:GridView ID="gvMatrix" runat="server"
AutoGenerateColumns="false" enableviewstate="false" showheaderwhenempty="true"
AllowSorting="True" emptydatatext="No Agents Listed" showfooter="true"
OnDataBound="OnDataBound" DataKeyNames="id" >
<Columns>
<asp:TemplateField HeaderText="Full Name" InsertVisible="False" SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newName" runat="server" placeholder="Full Name"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Role" InsertVisible="False" SortExpression="role">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("role") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtrole" runat="server" Text='<%# Bind("role") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newrole" runat="server" placeholder="Role"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Supervisor" InsertVisible="False" SortExpression="supervisor">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("supervisor") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtsupervisor" runat="server" Text='<%# Bind("supervisor") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newsupervisor" runat="server" placeholder="Supervisor"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" InsertVisible="False" SortExpression="location">
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("location") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtlocation" runat="server" Text='<%# Bind("location") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newlocation" runat="server" placeholder="Location"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Training Start Date" InsertVisible="False" SortExpression="trainingsdt">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("trainingsdt") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txttrainingsdt" runat="server" Text='<%# Bind("trainingsdt") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newtrainingsdt" runat="server" placeholder="Training Start Date"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Production Start Date" InsertVisible="False" SortExpression="Productionsdt">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Productionsdt") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtProductionsdt" runat="server" Text='<%# Bind("Productionsdt") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newProductionsdt" runat="server" placeholder="Production Start Date"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Terminated Date" InsertVisible="False" SortExpression="Terminateddate">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Terminateddate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtTerminateddate" runat="server" Text='<%# Bind("Terminateddate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newTerminateddate" runat="server" placeholder="Terminated Date"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" InsertVisible="False" SortExpression="notes">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtNotes" runat="server" Text='<%# Bind("notes") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="newNotes" runat="server" placeholder="Notes"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<ItemTemplate>
<asp:Button ID="InsertRecord" runat="server" Text="Add Record" CommandName="Insert" />
</ItemTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" showeditbutton="true"/>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" Text="Delete" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#3367a2" ForeColor="White" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#2461bf" Font-Bold="True" ForeColor="blue" HorizontalAlign="Center" />
<EditRowStyle CssClass="gridview_edit" />
<FooterStyle CssClass="GVFixedFooter" />
<AlternatingRowStyle BackColor="#eff3fb" ForeColor="#3367a2" HorizontalAlign="Center" />
</asp:GridView>
Code for Insert:
Protected Sub gvMatrix_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvMatrix.RowCommand
' Insert data if the CommandName == "Insert"
If e.CommandName = "Insert" AndAlso Page.IsValid Then
If rbSales.checked = True Then
SqlDataSource1.Insert()
Else
SqlDataSource2.Insert()
End If
End If
End Sub
Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Inserting
' Programmatically reference Web controls in the inserting interface...
Dim NewName As TextBox = _
gvMatrix.FooterRow.FindControl("NewName")
Dim NewRole As TextBox = _
gvMatrix.FooterRow.FindControl("NewRole")
Dim NewSupervisor As TextBox = _
gvMatrix.FooterRow.FindControl("NewSupervisor")
Dim NewLocation As TextBox = _
gvMatrix.FooterRow.FindControl("NewLocation")
Dim Newtrainingsdt As TextBox = _
gvMatrix.FooterRow.FindControl("Newtrainingsdt")
Dim Newproductionsdt As TextBox = _
gvMatrix.FooterRow.FindControl("Newproductionsdt")
Dim Newterminateddate As TextBox = _
gvMatrix.FooterRow.FindControl("Newterminateddate")
Dim NewNotes As TextBox = _
gvMatrix.FooterRow.FindControl("NewNotes")
' Set the ObjectDataSource's InsertParameters values...
e.command.parameters("Name").Value = NewName.Text
e.command.parameters("role").Value = NewRole.Text
e.command.parameters("supervisor").Value = NewSupervisor.Text
e.command.parameters("location").Value = NewLocation.Text
e.command.parameters("trainingsdt").Value = Newtrainingsdt.Text
e.command.parameters("productionsdt").Value = Newproductionsdt.Text
e.command.parameters("terminatedDate").Value = Newterminateddate.Text
e.command.parameters("notes").Value = NewNotes.Text
End Sub
I know its a lot to look at but again I feel my issue might not be with the code so much as me missing a concept. Thanks in advance for any ideas/suggestions.

Related

How to Enable a DropDownList in Gridview When Selected the First DropDownList

I'm working with my GridView table in ASP.Net.
First when I click the Edit link button in my GridView I will be able to edit it with Textbox and dropdownlist.
Here's the image of my GridView.
So the Business Unit was enabled but the Division, Sub-Division, Classification and Sub-Classification are not.
My problem is that when I select the Business Unit, the dropdownlist Division should be enabled and be able to select the value according to the Business Unit that I selected and so on. So the next dropdownlist will be dependent on the first dropdownlist that you selected. I searched about this on the internet already and tried different solutions but I'm still confused and don't know how it will work.
Here's my code in ASP.Net
<asp:GridView ID="gvGroup" runat="server" AllowPaging="false"
AllowSorting="true" AutoGenerateColumns="False" BorderColor="Silver"
BorderWidth="1px" Height="104px" ShowFooter="true" ShowHeader="true"
style="margin-right: 0px" Width="77%">
<RowStyle Font-Names="Arial" Font-Size="9pt" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField HeaderStyle-BackColor="#666666"
HeaderStyle-ForeColor="White" HeaderStyle-Width="10px" HeaderText=""
ItemStyle-Width="10px">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<HeaderStyle BackColor="#666666" ForeColor="White" />
<ItemStyle Width="10px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="140px" Visible="false">
<ItemTemplate>
<asp:Label ID="lblMasterID" runat="server" Text='<%#Bind("MASTERID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="140px" Visible="false">
<ItemTemplate>
<asp:Label ID="lblSEQID" runat="server" Text='<%#Bind("SEQID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Job Title" ItemStyle-Font-Size="9pt"
ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblJobTitle" runat="server" Text='<%#Bind("JOBTITLE") %>'
Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtJT" runat="server" CssClass="ehr_textbox"
Text='<%#BIND("JOBTITLE") %>' Width="140px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtJobTitleAdd" runat="server" Width="110px">
</asp:TextBox>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Business Unit"
ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblBusinessUnit" runat="server"
Text='<%#Bind("BUSINESS_UNIT") %>' Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_gvBusinessUnit" runat="server" CssClass="ehr_dropdown"
Width="140px">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlBusinessUnitAdd" runat="server" Width="110px">
</asp:DropDownList>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Division" ItemStyle-Font-Size="9pt"
ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblDivision" runat="server" Text='<%#Bind("DIVISION") %>'
Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_gvDivision" Enabled="false" runat="server" CssClass="ehr_dropdown"
Width="140px">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlDivisionAdd" runat="server" Width="110px">
</asp:DropDownList>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Sub-Division"
ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblSubDivision" runat="server" Text='<%#Bind("SUB_DIVISION") %>'
Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_gvSubDivision" Enabled="false" runat="server" CssClass="ehr_dropdown"
Width="140px">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSubDivisionAdd" runat="server" Width="110px">
</asp:DropDownList>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Classification"
ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblClassification" runat="server"
Text='<%#Bind("CLASSIFICATION") %>' Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_gvClassification" Enabled="false" runat="server"
CssClass="ehr_dropdown" Width="140px">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlClassification" runat="server" Width="110px">
</asp:DropDownList>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt"
HeaderStyle-ForeColor="White" HeaderText="Sub-Classification"
ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Label ID="lblSubClassification" runat="server"
Text='<%#Bind("SUB_CLASSIFICATION") %>' Width="140px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_gvSubClassification" Enabled="false" runat="server"
CssClass="ehr_dropdown" Width="140px">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSubClassification" runat="server" Width="110px">
</asp:DropDownList>
</FooterTemplate>
<HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
<ItemStyle Font-Size="9pt" Width="140px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#666666" ItemStyle-Font-Size="9pt">
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server" CommandName="Delete"
OnClientClick="return confirm('Do you want to delete?')" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnAdd" runat="server" CommandName="Add"
OnClick="AddgvGroup" Text="Add"></asp:LinkButton>
</FooterTemplate>
<HeaderStyle BackColor="#666666" />
<ItemStyle Font-Size="9pt" />
</asp:TemplateField>
<asp:CommandField HeaderStyle-BackColor="#666666" HeaderStyle-Width="10px"
ItemStyle-Font-Size="9pt" ItemStyle-Width="10px" ShowEditButton="True">
<HeaderStyle BackColor="#666666" />
<ItemStyle Font-Size="9pt" />
</asp:CommandField>
</Columns>
<PagerStyle Font-Size="9pt" HorizontalAlign="Right" />
<EmptyDataTemplate>
<div style="width: 100%; font-size: 10pt; text-align: center; color: Red;">
No record found.
</div>
</EmptyDataTemplate>
<HeaderStyle BackColor="DarkGray" Font-Bold="True" Font-Names="Arial"
Font-Size="9pt" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
And here's my code in VB.Net
Protected Sub gvGroup_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvGroup.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
Dim ddlBusinessUnit As DropDownList = DirectCast(e.Row.FindControl("ddl_gvBusinessUnit"), DropDownList)
'bind dropdown-list
Dim sqlstr As String
Dim dt As DataTable = New DataTable()
sqlstr = "Select BUSINESS_UNIT from BUSINESS_UNIT_TBL"
dt = ehr_utils.DataTable(sqlstr)
ddlBusinessUnit.DataSource = dt
ddlBusinessUnit.DataTextField = "BUSINESS_UNIT"
ddlBusinessUnit.DataValueField = "BUSINESS_UNIT"
ddlBusinessUnit.DataBind()
Dim dr As DataRowView = TryCast(e.Row.DataItem, DataRowView)
ddlBusinessUnit.SelectedValue = dr("BUSINESS_UNIT").ToString()
End If
End If
End Sub
Any idea of how can I possibly do that? And I tried also the OnSelectedIndexChanged
First you need to add an OnSelectedIndexChanged to ddl_gvBusinessUnit and set AutoPostBack to true
<asp:DropDownList ID="ddl_gvBusinessUnit" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl_gvBusinessUnit_SelectedIndexChanged">
And then in code behind
protected void ddl_gvBusinessUnit_SelectedIndexChanged(object sender, EventArgs e)
{
//cast the sender back to a dropdownlist
DropDownList dropDownList1 = sender as DropDownList;
//get the selectedvalue
string value = dropDownList1.SelectedValue;
//find the other dropdownlist in the correct row by using the editindex
DropDownList dropDownList2 = gvBusinessUnit.Rows[gvBusinessUnit.EditIndex].FindControl("DropDownList2") as DropDownList;
//do stuff with the other dropdownlist, like give it a color or add database values based on the first dropdownlist
dropDownList2.BackColor = Color.Red;
}
VB
Protected Sub ddl_gvBusinessUnit_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
'cast the sender back to a dropdownlist
Dim dropDownList1 As DropDownList = CType(sender,DropDownList)
'get the selectedvalue
Dim value As String = dropDownList1.SelectedValue
'find the other dropdownlist in the correct row by using the editindex
Dim dropDownList2 As DropDownList = CType(gvBusinessUnit.Rows(gvBusinessUnit.EditIndex).FindControl("DropDownList2"),DropDownList)
'do stuff with the other dropdownlist, like give it a color or add database values based on the first dropdownlist
dropDownList2.BackColor = Color.Red
End Sub

export gridview to excel is not working with Ajax and Update panel

I have a grid-view in Update panel. there is a link button inside grid-view which fire export command in row command event. There is an another grid-view which get exported on this command code. I debug, the pointers goes in but the export not happening. I know i am missing something here, but not able to get it after spending lot of hours. The Script manager is on master page.
Can any one help please. Below is the code.
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="grd_Report" runat="server" ShowFooter="true" CssClass="ui-jqgrid-btable table-hover" AutoGenerateColumns="false" AllowPaging ="true" PageSize ="12" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lbl_CampaignName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CreateDate">
<ItemTemplate>
<asp:Label ID="lbl_CreateDate" runat="server" Text='<%#Eval("CreateDate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="130px" />
<HeaderStyle Width="130px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="sender">
<ItemTemplate>
<asp:Label ID="lbl_senderID" runat="server" Text='<%#Eval("sender") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="85px" />
<HeaderStyle Width="85px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Text">
<ItemTemplate>
<asp:Label ID="lbl_text" runat="server" Text='<%#Eval("Text") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList class="ui-pg-selbox" ID="drp_itemCount" runat="server" AutoPostBack="true"
onselectedindexchanged="drp_itemCount_SelectedIndexChanged" >
<asp:listItem>10</asp:listItem>
<asp:listItem>15</asp:listItem>
<asp:listItem>50</asp:listItem>
<asp:listItem>100</asp:listItem>
<asp:listItem>200</asp:listItem>
</asp:DropDownList>
</FooterTemplate>
<ItemStyle Width="375px" />
<HeaderStyle Width="375px" />
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Count">
<ItemTemplate>
<asp:Label ID="lbl_SMSCount" runat="server" Text='<%#Eval("Count") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" width="80px" />
<HeaderStyle Width="80px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Delivery Count">
<ItemTemplate>
<table class="deliveryCount">
<tr>
<td style="padding:5px;width:180px" colspan="2">Total: <%#Eval("Total")%></td>
</tr>
<table style="font-size:11px;width:180px;">
<tr>
<td style="padding:5px;font-size:11px;width:80px">A: <%#Eval("A")%></td>
<td style="padding:5px;font-size:11px;width:80px">B: <%#Eval("B")%></td>
</tr
<tr>
<td style="padding:5px;font-size:11px;width:80px">2: <%#Eval("2")%></td>
<td style="padding:5px;font-size:11px;width:80px">1: <%#Eval("1")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnk_download" style="font-size:11px;" CommandName="download" CommandArgument='<%#Eval("CampaignId") %>' text="Download" class="ui-icon-document"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" width="100px" />
<HeaderStyle Width="100px" />
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Center" Font-Size="13" Font-Bold="true" />
<RowStyle Font-Names="Helvetica" Font-Size="10" />
<PagerStyle CssClass ="gridviewPager" Height="30px" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="grd_export" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel6" runat="Server">
<ContentTemplate>
<asp:GridView ID="grd_export" runat="server" Visible="false" AutoGenerateColumns ="false" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lbl_Name" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:Label ID="lbl_Number" runat="server" Text='<%#Eval("Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="lbl_Id" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Text">
<ItemTemplate>
<asp:Label ID="lbl_text" runat="server" Text='<%#Eval("Text") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="text Id">
<ItemTemplate>
<asp:Label ID="lbl_MessageId" runat="server" Text='<%#Eval("textId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbl_Date" runat="server" Text='<%#Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Credits">
<ItemTemplate>
<asp:Label ID="lbl_Credits" runat="server" Text='<%#Eval("Credits") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Below is the code on Row Command event
If e.CommandName = "download" Then
Dim str As String
str = " select * FROM [Box] where MsgId='" + e.CommandArgument + "'"
Dim com As New SqlCommand(str, con)
Dim da As New SqlDataAdapter(com)
Dim dt As New DataTable
da.Fill(dt)
If Not dt Is Nothing Then
If dt.Rows.Count > 0 Then
grd_export.DataSource = dt
grd_export.DataBind()
grd_export.Visible = True
Response.Clear()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.AddHeader("content-disposition", "attachment;filename=Message.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Me.EnableViewState = False
Dim stringwrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlwrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringwrite)
grd_export.RenderControl(htmlwrite)
Response.Write(stringwrite.ToString())
grd_export.Visible = False
Response.End()
End If
End If
End If
You need to add a postback trigger to your update panel for respose.write to work.

Accessing Linkbutton click event in footer of Gridview

I am working on an asp.net project where I have a gridview on the default.aspx page databound to my sql database. When I click on a specific row it navigates to a details.aspx page where you can see and edit the details of the row clicked.
On that details.aspx page is another gridview where I exposed the footer and added and "Insert" linkbutton and the appropriate controls for each column to add a new record into the database. I have the entire project coded, but unfortunately nothing happens when I click on "Insert" linkbutton (Except the text in the controls all clear). No exceptions are thrown, but no record is added to the database. Here is the gridview code:
<asp:GridView ID="grid1" runat="server" AutoGenerateColumns="False" DataKeyNames="ClientId" DataSourceID="SqlDataSource1" ShowFooter="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="ClientId" InsertVisible="False" SortExpression="ClientId">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ClientId") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ClientId") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbInsert" runat="server" CommandName="insert" CausesValidation="false">Insert</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MiddleName" SortExpression="MiddleName">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MiddleName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("MiddleName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMiddleName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gender" SortExpression="Gender">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Gender") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Gender") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddGender" runat="server">
<asp:ListItem>M</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DateOfBirth" SortExpression="DateOfBirth">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("DateOfBirth") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("DateOfBirth") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode" SortExpression="ZipCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("ZipCode") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtZIP" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
and here is the codebehind:
Private Sub grid1_RowCommand1(sender As Object, e As GridViewCommandEventArgs) Handles grid1.RowCommand
If e.CommandName = "insert" Then
SqlDataSource1.InsertParameters("FirstName").DefaultValue = DirectCast(grid1.FooterRow.FindControl("txtFirstName"), TextBox).Text
SqlDataSource1.InsertParameters("MiddleName").DefaultValue = DirectCast(grid1.FooterRow.FindControl("txtMiddleName"), TextBox).Text
SqlDataSource1.InsertParameters("LastName").DefaultValue = DirectCast(grid1.FooterRow.FindControl("txtLastName"), TextBox).Text
SqlDataSource1.InsertParameters("Gender").DefaultValue = DirectCast(grid1.FooterRow.FindControl("ddGender"), DropDownList).SelectedValue
SqlDataSource1.InsertParameters("DateOfBirth").DefaultValue = DirectCast(grid1.FooterRow.FindControl("txtDOB"), TextBox).Text
SqlDataSource1.InsertParameters("ZipCode").DefaultValue = DirectCast(grid1.FooterRow.FindControl("txtZIP"), TextBox).Text
SqlDataSource1.Insert()
End If
End Sub
Thanks for any assistance in sorting this out!
John
DefaultValue doesn't set the value of what should be inserted, but rather provides resolution for null values for types that don't allow them (Integer, Long, etc). See this link for more information on what that Property does.
What you'll want to do is use Control Parameters in your SqlDataSource to bind the values of your TextBoxes to the parameters used by the InsertCommand. Use the following as an example:
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:YourConnection%>"
insertcommand="INSERT INTO SomeTable (FirstName, MiddleName) VALUES (#FirstName, #MiddleName)">
<insertparameters>
<asp:controlparameter name="FirstName" controlid="txtFirstName" propertyname="Text"/>
<asp:controlparameter name="MiddleName" controlid="txtLastName" propertyname="Text"/>
</insertparameters>
</asp:sqldatasource>
Then your grid1_RowCommand1 method becomes much cleaner:
Private Sub grid1_RowCommand1(sender As Object, e As GridViewCommandEventArgs) Handles grid1.RowCommand
If e.CommandName = "insert" Then
SqlDataSource1.Insert()
End If
End Sub

Input Value to Item template with diffrent query and get parameter value from the gridview

i Want to add on column on aspx page, and the value is comes from diffrent query,
here's my datagridview on aspx :
<asp:Panel ID="pnlGrid" runat="server" align="center">
<asp:Label ID="lbldgTime" runat="server" Text=" "></asp:Label><br />
<asp:GridView ID="gvData" runat="server" AllowPaging="True" AutoGenerateColumns="False"
EmptyDataText="No data available." CellPadding="4" DataKeyNames="PayId" Font-Size="13px"
ForeColor="Black" PageSize="20" Width="100%" Style="text-align: center">
<Columns>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" Width="20px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Img/view.png" runat="server" Width="25"
Height="25" OnClick="imgbtn_Click" />
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No Account">
<ItemStyle HorizontalAlign="Center" Width="100px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblNoaccount" runat="server" Text='<%# Bind("PayAccount") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemStyle HorizontalAlign="Center" Width="150px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblCustName" runat="server" Text='<%# Bind("PayCustName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemStyle HorizontalAlign="Center" Width="20px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Bind("PayAmount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount Paid">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblRefNo" runat="server" Text='<%# Bind("PayRefNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Response">
<ItemStyle HorizontalAlign="Center" Width="70px" />
<FooterStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblResponse" runat="server" Text='<%# Bind("PayResponse") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
the field :
<asp:TemplateField HeaderText="Response">
<ItemStyle HorizontalAlign="Center" Width="70px" />
<FooterStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblResponse" runat="server" Text='<%# Bind("PayResponse") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
the value is comes from diffrent query when fill the datagrid,
and here's the code behind of my datagrid :
Sub FillData()
Try
Dim dt As New DataTable
Me.lbleMessage.Text = ""
If txtDate.Text = "__/__/____" Then
txtDate.Text = ""
End If
If CPayment.SearchPayment(txtAccount.Text.Trim, txtCustName.Text.Trim, txtAmount.Text, txtAmountPaid.Text, dropResponse.SelectedValue.ToString, txtRefNo.Text.Trim, txtDate.Text) Then
dt = CPayment.DT
Else
eMessage("System failure: ", CPayment.eMsg)
End If
Dim RC As Integer = dt.Rows.Count
totalrows = RC
If RC = 0 Then
'dt.Rows.Add()
dt.Clear()
gvData.DataSource = dt.DefaultView
gvData.DataBind()
eMessage("", "There are no row to display.")
Else
gvData.DataSource = dt.DefaultView
gvData.DataBind()
gvData.BottomPagerRow.Visible = True
End If
Catch ex As Exception
eMessage("Load Data failure: ", ex.ToString())
End Try
End Sub
and here's the query for the response field :
Public Function Revstatus(ByVal PayRefNo As String) As Boolean
Dim strsql As String = " Select COUNT(*) from payment(Pay) inner(Join) Reversal(Rev) on Pay.PayRefNo = Rev.PayRefNo where Pay.PayRefNo ='%" & PayResponse & "%'"
Return runQuery(strsql)
End Function
the ByVal PayRefNo As String parameter comes from
<asp:TemplateField HeaderText="Amount Paid">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblRefNo" runat="server" Text='<%# Bind("PayRefNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
is it possible to input differnce query on datagrid while fill it ?
ahhhhh... finnaly i found the way.
on datagridview row bound i did this :
If e.Row.RowType = DataControlRowType.DataRow Then
Dim RefNo As Label = CType(e.Row.FindControl("lblRefNo"), Label)
If CPayment.Revstatus(RefNo.Text) Then
CType(e.Row.FindControl("lblRevResp"), Label).Text = "Reversed"
Else
CType(e.Row.FindControl("lblRevResp"), Label).Text = "Paid"
End If
End If

dropdown list won't polpuate values from database

I'm stuck with a problem to populate a DropDownList control with values from the database using item field template in read only mode. I appreciate a detailed explanation, since I'm new to ASP.NET. Below is the code and the error I'm getting:
'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
The code for this is :
<asp:SqlDataSource ID="categoriesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand ="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = #UserId)">
<SelectParameters>
<asp:ControlParameter ControlID="UserIdValue"
Name="UserId"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="UserIdValue" runat="server" Visible="False"></asp:Label>
<asp:GridView ID="gvPictures"
runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
CellPadding="4"
DataKeyNames="PictureID"
DataSourceID="picturesDataSource"
ForeColor="#333333"
GridLines="None" Width="800px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True"
ValidationGroup="PictureEdit" />
<asp:TemplateField HeaderText="Category"
SortExpression="CategoryID">
<EditItemTemplate>
<asp:DropDownList ID="pictureEditCategories"
runat="server"
AppendDataBoundItems="True"
DataSourceID="categoriesDataSource"
DataTextField="Name"
DataValueField="CategoryID"
SelectedValue='<%# Bind("CategoryID") %>'>
<asp:ListItem Value="" Text="--Select Category -- "/>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="PictureReadOnlyCategories"
runat="server"
AppendDataBoundItems="True"
DataSourceID="categoriesDataSource"
DataTextField="Name"
DataValueField="CategoryID"
Enabled="False"
SelectedValue='<%# Bind("CategoryID") %>'>
<asp:ListItem Selected="True" Value="">-- No Category --</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server"
EnableViewState="False"
Text='<%# Bind("Title") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server"
ControlToValidate="TextBox1"
Display="Dynamic"
ErrorMessage="must enter a title"
ValidationGroup="PictureEdit">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1"
runat="server"
Text='<%# Bind("Title") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox2"
runat="server"
Columns="25"
Rows="4"
Text='<%# Bind("Description") %>'
TextMode="MultiLine">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5"
runat="server"
ControlToValidate="TextBox2"
Display="Dynamic"
ErrorMessage="you must enter a description"
ValidationGroup="PictureEdit">
</asp:RequiredFieldValidator><
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2"
runat="server"
Text='<%# Bind("Description") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Added" SortExpression="UploadedOn">
<EditItemTemplate>
<asp:Label ID="Label4"
runat="server"
Text='<%# Bind("UploadedOn") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3"
runat="server"
Text='<%# Bind("UploadedOn") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageUrlField="PictureID"
DataImageUrlFormatString="~/UploadedImages/{0}.jpg"
HeaderText="Image"
ReadOnly="True">
<ControlStyle Width="100px" />
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
You need to make sure that you are binding the PictureReadOnlyCategories DDL to populate the items before you are binding the selected item. The problem looks like it is with the order things are being done and that is all. If you try to select an item in a DDL that does not exist then you get that error.

Resources