ASP.NET ObjectDataSource, change CommandName property of FormView Button - asp.net

I have an ObjectDataSource that I'm using with a FormView, and it works fine, but i want to change one small thing. On the FormView the button that fires the update has the CommandName attribute set to "Update," but I would like to change that attribute to something other than "Update" - when I do change that attribute the update no longer works. The reason I want to do this is I have multiple FormViews on the same page and need to have multiple update buttons. Below is my code:
FormView:
<asp:FormView ID="fvGeneralInfo" runat="server"
DataSourceID="objInstructorDetails" CssClass="Gridview"
OnItemCommand="fvGeneralInfo_ItemCommand"
DefaultMode="Edit">
<EditItemTemplate>
<table>
....
<tr>
<td style="text-align:right;">
<asp:Label runat="server" ID="lblGeneralInfoMessage" Text="General Info updated successfully" Visible="false" />
</td>
<td>
<asp:Button runat="server" ID="btnUpdateGeneralInfo" ValidationGroup="UpdateGeneralInfo" Text="Update" CommandName="Update" />
<asp:Button runat="server" ID="btnCancelGeneralInfo" Text="Cancel" CommandName="CancelGeneralInfo" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
ObjectDataSource:
<asp:ObjectDataSource ID="objInstructorDetails" runat="server" TypeName="AIMLibrary.BLL.Instructor" SelectMethod="GetInstructorDetails"
InsertMethod="InsertInstructor" UpdateMethod="UpdateInstructor" OnInserting="objInstructorDetails_OnInserting"
OnUpdating="objInstructorDetails_OnUpdating" >
<SelectParameters>
<asp:QueryStringParameter Name="InstructorId" QueryStringField="InstructorId" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="instructorId" Type="Int32" />
<asp:Parameter Name="firstName" Type="String" DefaultValue="" />
<asp:Parameter Name="middleName" Type="String" DefaultValue="" />
<asp:Parameter Name="lastName" Type="String" DefaultValue="" />
<asp:Parameter Name="phone" Type="String" DefaultValue="" />
<asp:Parameter Name="email" Type="String" DefaultValue="" />
<asp:Parameter Name="addressLine1" Type="String" DefaultValue="" />
<asp:Parameter Name="addressLine2" Type="String" DefaultValue="" />
<asp:Parameter Name="city" Type="String" DefaultValue="" />
<asp:Parameter Name="state" Type="String" DefaultValue="" />
<asp:Parameter Name="zip" Type="String" DefaultValue="" />
<asp:Parameter Name="abcBoardNumber" Type="String" DefaultValue="" />
</UpdateParameters>
</asp:ObjectDataSource>

Each FormView will have it's own event for handling updates so the CommandName being the same for different FormViews should not be a problem.
You can change the name of the buttons if that's an issue by changing it's text value.

Related

How to make new command work in gridview asp.net

I have a gridview, in the gridview task, I choose Edit Column-> Selected Fields->Command Field.select insert button to True. And the New link field appear, and I check the HTML Source,
look like necessary codes are there, but when I click on the "New" link field, no response at all, but update is ok for me, delete I have not tested yet.
Below are codes for the gridview and sqldatasource :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="agreement_no,id" Font-Size="9pt" DataSourceID="SqlDataSource1" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True"></asp:CommandField>
<asp:BoundField DataField="agreement_no" HeaderText="agreement_no" ReadOnly="True" SortExpression="agreement_no"></asp:BoundField>
<asp:TemplateField HeaderText="status" SortExpression="status">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="status" DataValueField="status" SelectedValue='<%# Bind("status") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [status] FROM [deal_master]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sales_person" HeaderText="sales_person" SortExpression="sales_person"></asp:BoundField>
<asp:BoundField DataField="swap_carrier" HeaderText="swap_carrier" SortExpression="swap_carrier"></asp:BoundField>
<asp:BoundField DataField="start_pos" HeaderText="start_pos" SortExpression="start_pos"></asp:BoundField>
<asp:BoundField DataField="end_pos" HeaderText="end_pos" SortExpression="end_pos"></asp:BoundField>
<asp:BoundField DataField="swap_commitment" HeaderText="swap_commitment" SortExpression="swap_commitment"></asp:BoundField>
<asp:BoundField DataField="zone" HeaderText="zone" SortExpression="zone"></asp:BoundField>
<asp:BoundField DataField="target_minutes" HeaderText="target_minutes" SortExpression="target_minutes"></asp:BoundField>
<asp:BoundField DataField="target_sell_rate" HeaderText="target_sell_rate" SortExpression="target_sell_rate"></asp:BoundField>
<asp:BoundField DataField="target_buy_rate" HeaderText="target_buy_rate" SortExpression="target_buy_rate"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="supplier_interconnect" HeaderText="supplier_interconnect" SortExpression="supplier_interconnect"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="customer_interconnect" HeaderText="customer_interconnect" SortExpression="customer_interconnect"></asp:BoundField>
<asp:BoundField DataField="target_sales" HeaderText="target_sales" SortExpression="target_sales"></asp:BoundField>
<asp:BoundField DataField="target_cost" HeaderText="target_cost" SortExpression="target_cost"></asp:BoundField>
<asp:BoundField DataField="target_profit" HeaderText="target_profit" SortExpression="target_profit"></asp:BoundField>
<asp:BoundField DataField="lcr_zone" HeaderText="lcr_zone" SortExpression="lcr_zone"></asp:BoundField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" DeleteCommand="DELETE FROM [deal_master] WHERE [agreement_no] = #agreement_no AND [id] = #id" InsertCommand="INSERT INTO [deal_master] ([agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id]) VALUES (#agreement_no, #status, #sales_person, #swap_carrier, #start_pos, #end_pos, #swap_commitment, #zone, #target_minutes, #target_sell_rate, #target_buy_rate, #supplier_interconnect, #customer_interconnect, #target_sales, #target_cost, #target_profit, #lcr_zone, #id)" SelectCommand="SELECT [agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id] FROM [deal_master]" UpdateCommand="UPDATE [deal_master] SET [status] = #status, [sales_person] = #sales_person, [swap_carrier] = #swap_carrier, [start_pos] = #start_pos, [end_pos] = #end_pos, [swap_commitment] = #swap_commitment, [zone] = #zone, [target_minutes] = #target_minutes, [target_sell_rate] = #target_sell_rate, [target_buy_rate] = #target_buy_rate, [supplier_interconnect] = #supplier_interconnect, [customer_interconnect] = #customer_interconnect, [target_sales] = #target_sales, [target_cost] = #target_cost, [target_profit] = #target_profit, [lcr_zone] = #lcr_zone WHERE [agreement_no] = #agreement_no AND [id] = #id">
<DeleteParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [agreement_no] FROM [deal_master] ORDER BY [agreement_no]"></asp:SqlDataSource>
<br />
<br />
<div>
</div>
enter image description here
my question is : what is the actions or setting I missed?
I want to know what steps I missed?
My objective is : I want to click on the "New" linkfield then 1 empty row appear, then I input the value in the new created row and I can save it or cancel it
If you look at the documentation for the GridView control, it says:
Inserting records into the data source is not directly supported by the GridView control. However, it is possible to insert records by using the GridView control in conjunction with the DetailsView or FormView control. For more information, see DetailsView or FormView, respectively.
Additionally, the CommandField documentation states about the ShowInsertButton property:
This property applies only to data-bound controls that support insert operations, such as the DetailsView control.
So, you'll need to create your own form separately, or leverage a DetailsView or FormView. Or better yet: ditch Web Forms altogether if you can, as it's a dead platform, as I explain on my blog.

Detailsview templatefield mapping to ObjectDataSource?

I need help to understand the proper way to map or associate TemplateFields to the ObjectDataSource. I show only one (of many) template definitions here:
<asp:TemplateField HeaderText="First Name" SortExpression="cFIRSTNAME">
<ItemTemplate>
<asp:Label ID="lblValFirstName" runat="server" Text='<%# Eval("cFIRSTNAME") %>' style="font-weight: bold;" ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("cFIRSTNAME") %>' MaxLength="20"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("cFIRSTNAME") %>' MaxLength="20"></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
The ObjectDataSource and update parameters are:
<asp:ObjectDataSource ID="ODS_LOGIN_DETAILS" runat="server"
SelectMethod="GetLOGINSbyLoginID"
TypeName="bllLOGINS"
DeleteMethod="DeleteFromDetailsView"
InsertMethod="InsertFromDetailsView"
UpdateMethod="UpdateFromDetailsView" OldValuesParameterFormatString="original_{0}"> <UpdateParameters>
<asp:Parameter Name="p_UID_LOGIN" Type="Int32" />
<asp:Parameter Name="p_UID_CONTACT" Type="Int32" />
<asp:Parameter Name="p_UID_USER_TYPE" Type="Int32" />
<asp:Parameter Name="p_TXT_USERNAME" Type="String" />
<asp:Parameter Name="p_TXT_PASSWORD" Type="String" />
<asp:Parameter Name="p_BOOL_IS_ACTIVE" Type="Boolean" />
<asp:Parameter Name="p_DT_END" Type="DateTime" />
<asp:Parameter Name="p_FirstName" Type="String" />
<asp:Parameter Name="p_LastName" Type="String" />
<asp:Parameter Name="p_CONTACTTITLE" Type="String" />
<asp:Parameter Name="p_TXT_PHONE" Type="String" />
<asp:Parameter Name="p_CONTACT_EMAIL" Type="String" /> </UpdateParameters>
What is NOT clear to me is how is the mapping made from the templatefield textbox (txtFirstName) to the UpdateParameter "p_FirstName"?
In the existing code I am working with, I see the ObjectDataSource_Updating()-event that does a series of DVW.FindControl() values being assigned/set to the
e.InputParameter("param-name") = text-box-value
Questions?
Is this done in either the ObjectDataSource_Updating()-event or in the DetailsView_Updtaing()-event -or- by declaration aspx code?
or how?
What is the best way to do this?
Would naming the textbox-ID and the parameter-name simplify the code?
I am assuming the solutions offered would be "similar" or the same as with SqlDataSource -- please confirm?
Thanks in advance...John
I had a similar problem and was unsure how to map the textbox to the params as was getting NULL param value passed when doing a SQL trace. In the end I set the parameter name to match the value in the Text attribute bind which worked.
<UpdateParameters>
<asp:Parameter Name="my_field" Type="String" Direction="Input" />
...
<asp:TextBox Text='<%# Bind("my_field") %>'...

detailed information for each entry in gridview

So i have made a Web Form with a dropdownlist which contains different classes in school and if you select one you get all the students of the selected class in the GridView below. So what i want to make now is, that if i click on a student it should open a more detailed page about the student, but i have no clues how to do this. I get all my data of a .mdf database file.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="schueler.aspx.cs" Inherits="ASPXUebung.schueler" %>
<asp:DropDownList ID="selectklassen" runat="server" DataSourceID="SqlDataSource1klassenselect" DataTextField="K_Bez" DataValueField="K_ID" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1klassenselect" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [K_Bez], [K_ID] FROM [klassen] ORDER BY [K_Bez]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1schueler" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [schueler] WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))" InsertCommand="INSERT INTO [schueler] ([S_SCHNR], [S_Name], [S_Vorname], [S_Gebdat], [S_Adresse], [S_K_Klasse]) VALUES (#S_SCHNR, #S_Name, #S_Vorname, #S_Gebdat, #S_Adresse, #S_K_Klasse)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [schueler] WHERE ([S_K_Klasse] = #S_K_Klasse)" UpdateCommand="UPDATE [schueler] SET [S_Name] = #S_Name, [S_Vorname] = #S_Vorname, [S_Gebdat] = #S_Gebdat, [S_Adresse] = #S_Adresse, [S_K_Klasse] = #S_K_Klasse WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="S_SCHNR" Type="Int16" />
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="selectklassen" Name="S_K_Klasse" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Make the student name column a Hyperlink column like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="S_SCHNR"
DataNavigateUrlFormatString="StudentInfo.aspx?id={0}
DataTextField="S_Name" "/>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
Make another web page called StudentInfo.aspx. On that page, display the data using a DetailsView control, a SqlDataSource control and the QueryString parameter. Here's an example of how to do that: http://msdn.microsoft.com/en-us/library/xt50s8kz(v=vs.100).aspx
A more convenient way to do this without creating a new page would be to populate the data into a Bootstrap modal like this. It uses UpdatePanel, which may or may not be something you want to use though.
Add the Detail Event to the Gridview.
Create a div for the Bootstrap modal with a FormView
Call the jQuery from the C# code behind to populate the data in the FormView with the ID from the GridView.

How to instruct ObjectDataSource to match form parameter with method parameter

When working with ObjectDataSource I have following select:
<asp:DropDownList runat="server" SelectedValue='<%# Bind("InceptionCycle.ID") %>' ID="InceptionCycle"
DataSourceID="odsAllCycles" DataTextField="CycleName" DataValueField="ID" AppendDataBoundItems="true">
<asp:ListItem Text="Choose..." Value=""></asp:ListItem>
</asp:DropDownList>
and ObjectDataSource configured with UpdateMethod and InsertMethod. However insert/update methods have parameters with InceptionCycle name (because InceptionCycle.ID is not valid identifier).
Is there a way to instruct ObjectDataSource to take InceptionCycle.ID form parameter and place in as InceptionCycle method parameter?
Here's full ObjectDataSource code:
<asp:ObjectDataSource ID="ods" runat="server" TypeName="Sources.DomainSource"
SelectMethod="FindById" InsertMethod="Add" UpdateMethod="Update"
OnInserted="ods_Inserted" OnUpdated="ods_Updated">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</SelectParameters>
<InsertParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
</InsertParameters>
<UpdateParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
</UpdateParameters>
</asp:ObjectDataSource>
You can only use the Bind syntax with a top level property - it doesn't support nested properties (VS 2012 will, though).
So, you should create a new property on your data source like below and bind the SelectedValue to this new property instead
public string InceptionCycleID
{
get
{
return InceptionCycle.ID;
}
set
{
InceptionCycle.ID = value;
}
}

Can not update Column bound by an Image field in gridview asp.net

I have three columns in my Grid view named TweetText, TweetImageUrl and an Column of ImageFied
whose DataImageUrl Field is TweetImageURl. My problem is that When i use the Edit,update feature of grid, I cant edit/update the TweetImageUrl but I can Update TweetText. But when I remove The ImageField Column then I can update the TweetImageUrl Column too. So Can anyone help so that i can Update the TweetImageUrl with ImageField there in Grid Too?
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="TwitterUserId"
DataSourceID="SqlDataSource1" onrowcommand="GridView1_RowCommand"
PageSize="14" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Approve" runat="server"
CommandName="Approve"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Approve" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TweetText" HeaderText="TweetText"
SortExpression="TweetText" />
<asp:BoundField DataField="TweetImageUrl" HeaderText="TweetImageUrl"
SortExpression="TweetImageUrl" />
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px"
NullImageUrl="~/Admin/ajax-loader.gif">
</asp:ImageField>
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:mistersmartyplantsConnectionString %>"
DeleteCommand="DELETE FROM [TwitterData] WHERE [TwitterUserId] = #original_TwitterUserId AND (([TweetId] = #original_TweetId) OR ([TweetId] IS NULL AND #original_TweetId IS NULL)) AND (([TwitterUserName] = #original_TwitterUserName) OR ([TwitterUserName] IS NULL AND #original_TwitterUserName IS NULL)) AND (([TweetText] = #original_TweetText) OR ([TweetText] IS NULL AND #original_TweetText IS NULL)) AND (([TweetImageUrl] = #original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND #original_TweetImageUrl IS NULL)) AND (([TwitterDate] = #original_TwitterDate) OR ([TwitterDate] IS NULL AND #original_TwitterDate IS NULL))"
InsertCommand="INSERT INTO [TwitterData] ([TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate]) VALUES (#TweetId, #TwitterUserId, #TwitterUserName, #TweetText, #TweetImageUrl, #TwitterDate)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate] FROM [TwitterData] WHERE ([Approved] = #Approved) ORDER BY [TwitterDate] DESC"
UpdateCommand="UPDATE [TwitterData] SET [TweetId] = #TweetId, [TwitterUserName] = #TwitterUserName, [TweetText] = #TweetText, [TweetImageUrl] = #TweetImageUrl, [TwitterDate] = #TwitterDate WHERE [TwitterUserId] = #original_TwitterUserId AND (([TweetId] = #original_TweetId) OR ([TweetId] IS NULL AND #original_TweetId IS NULL)) AND (([TwitterUserName] = #original_TwitterUserName) OR ([TwitterUserName] IS NULL AND #original_TwitterUserName IS NULL)) AND (([TweetText] = #original_TweetText) OR ([TweetText] IS NULL AND #original_TweetText IS NULL)) AND (([TweetImageUrl] = #original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND #original_TweetImageUrl IS NULL)) AND (([TwitterDate] = #original_TwitterDate) OR ([TwitterDate] IS NULL AND #original_TwitterDate IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="No" Name="Approved" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Use
<asp:TemplateField HeaderText="Images" ItemStyle-Height="10px" ItemStyle-Width="10px" >
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval(TweetImageUrl) %>' Height="10px" Width="10px" />
</ItemTemplate>
</asp:TemplateField>
Rather then
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px" NullImageUrl="~/Admin/ajax-loader.gif"></asp:ImageField>
Hope It Helps. Good Luck.

Resources