I have a textbox with ID="txtAnswer" in my DetailView EditItemTemplate, where need it in my DataSourse UpdateCommand, I read other relating threads, and try some of the ways i either get an error, or the update took place without the txtAnswer value being
updated!
Here is the DetailView Code:
<asp:DetailsView ID="DetailsView1" runat="server"
Height="50px"
DefaultMode="Edit"
DataSourceID="SqlDataSource2"
AutoGenerateRows="false"
DataKeyNames="ID"
FieldHeaderStyle-Width="150px"
Width="600px"
>
<Fields>
<asp:TemplateField HeaderText=":نام و نام خوانوادگی" SortExpression="FirstName" >
Hi abets, i had try your code it works with the item bind, but when i try to update the data inside detail view, i got this error:
Parameter '@MailAdd1' must be defined.
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: MySql.Data.MySqlClient.MySqlException: Parameter '@MailAdd1' must be defined.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
says to defined the parameter, i know if bound the data, there is a datafield, but how to defined datafield for the MailAdd1? My code below:
abets
Member
11 Points
45 Posts
cant assign a textbox.Text in DetailView EditItemTemplate to a contorlParameter
Oct 16, 2009 10:42 AM|LINK
Hello
I have a textbox with ID="txtAnswer" in my DetailView EditItemTemplate, where need it in my DataSourse UpdateCommand, I read other relating threads, and try some of the ways i either get an error, or the update took place without the txtAnswer value being updated!
Here is the DetailView Code:
<asp:DetailsView ID="DetailsView1" runat="server"
Height="50px"
DefaultMode="Edit"
DataSourceID="SqlDataSource2"
AutoGenerateRows="false"
DataKeyNames="ID"
FieldHeaderStyle-Width="150px"
Width="600px"
>
<Fields>
<asp:TemplateField HeaderText=":نام و نام خوانوادگی" SortExpression="FirstName" >
<ItemTemplate><%# ReturnFixlenghtText(Eval("FirstName").ToString(),50,".") %> <%# ReturnFixlenghtText(Eval("LastName").ToString(),50,".") %> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="سوال:" >
<ItemTemplate><%# ReturnFixlenghtText(Eval("Question").ToString(),800,"...")%></ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="پست الکتیریک" DataField="Email" ReadOnly="true" />
<asp:BoundField HeaderText="رتبه" DataField="Sort" ReadOnly="false" />
<asp:CheckBoxField HeaderText="انتشار" DataField="Publish" ReadOnly="false" />
<asp:TemplateField>
<HeaderTemplate>جواب:</HeaderTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAsnwer" TextMode="MultiLine" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" UpdateText="ثبت" ShowCancelButton="false" />
</Fields>
</asp:DetailsView>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:DetailsView ID="DetailsView1" runat="server"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Height="50px" </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> DefaultMode="Edit" </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> DataSourceID="SqlDataSource2" </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> AutoGenerateRows="false"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> DataKeyNames="ID"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> FieldHeaderStyle-Width="150px"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Width="600px"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <Fields></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TemplateField HeaderText=":نام و نام خوانوادگی" SortExpression="FirstName" > </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <ItemTemplate><%# ReturnFixlenghtText(Eval("FirstName").ToString(),50,".") %> <%# ReturnFixlenghtText(Eval("LastName").ToString(),50,".") %> </ItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TemplateField HeaderText="سوال:" ></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <ItemTemplate><%# ReturnFixlenghtText(Eval("Question").ToString(),800,"...")%></ItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField HeaderText="پست الکتیریک" DataField="Email" ReadOnly="true" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField HeaderText="رتبه" DataField="Sort" ReadOnly="false" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CheckBoxField HeaderText="انتشار" DataField="Publish" ReadOnly="false" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <HeaderTemplate>جواب:</HeaderTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <EditItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TextBox runat="server" ID="txtAsnwer" TextMode="MultiLine" ></asp:TextBox></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </EditItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CommandField ShowEditButton="true" UpdateText="ثبت" ShowCancelButton="false" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </Fields> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:DetailsView></div>And here is my SQLDataSource code:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalSqlServer%>"
DataSourceMode="DataReader"
SelectCommand="SELECT [ID]
,[FirstName]
,[LastName]
,[Email]
,[Question]
,[Answer]
,[Status]
,[Publish]
,[Sort]
FROM [PranicHealingDB].[dbo].[FAQ]
WHERE ID = @ID
"
UpdateCommand="UPDATE [PranicHealingDB].[dbo].[FAQ]
SET [Publish] = @Publish
,[Sort] = @Sort
,[Answer] = @Answer
WHERE ID = @ID "
>
<SelectParameters>
<asp:ControlParameter Name="ID" ControlID="GridView1"
PropertyName="SelectedDataKey.Value" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="Answer" ControlID="ctl00$ContentPlaceHolder1$DetailsView1$txtAsnwer" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
with this ControlParameter i didnt get any error, but the update takes place without the txtAnswer value being updated,
Any help, i would appreciate alot
edit DetailView Edit Template dropdownlist gridview
abets
Member
11 Points
45 Posts
Re: cant assign a textbox.Text in DetailView EditItemTemplate to a contorlParameter
Oct 17, 2009 12:23 PM|LINK
it is solved, actually there wasnt any problem,
I hadnt bound the txtAnswer to the datacontainer, so i wouldnt notice if it was updating it,
here is the code of i bound it,
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <HeaderTemplate>جواب:</HeaderTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <EditItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TextBox runat="server" ID="txtAsnwer" Text='<%#DataBinder.Eval(Container.DataItem, "Answer")%>' TextMode="MultiLine" ></asp:TextBox></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </EditItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:TemplateField></div><asp:TemplateField>
<HeaderTemplate>جواب:</HeaderTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAsnwer" Text='<%#DataBinder.Eval(Container.DataItem, "Answer")%>' TextMode="MultiLine" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
ja
Member
47 Points
141 Posts
Re: cant assign a textbox.Text in DetailView EditItemTemplate to a contorlParameter
Oct 30, 2009 02:22 AM|LINK
Hi abets, i had try your code it works with the item bind, but when i try to update the data inside detail view, i got this error:
Parameter '@MailAdd1' must be defined.
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: MySql.Data.MySqlClient.MySqlException: Parameter '@MailAdd1' must be defined.
Source Error:
says to defined the parameter, i know if bound the data, there is a datafield, but how to defined datafield for the MailAdd1? My code below:
<asp:TemplateField SortExpression="MailAdd1" AccessibleHeaderText="MailAdd1">
<HeaderTemplate>
Address 1:
</HeaderTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtMailAdd1" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "MailAdd1")%>'
TextMode="MultiLine" Width="200px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Can you show how to do this,
I had do many google but i didn't find any solution for this prob
Thanks
code
abets
Member
11 Points
45 Posts
Re: cant assign a textbox.Text in DetailView EditItemTemplate to a contorlParameter
Nov 02, 2009 09:42 AM|LINK
hey ja,
i guess you forgot to write the update parameter for your SQLDataSource, you shuold a code like this to you SQLDataSource
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><UpdateParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:ControlParameter Name="Answer" ControlID="ctl00$ContentPlaceHolder1$DetailsView1$txtAsnwer" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </UpdateParameters></div><UpdateParameters>
<asp:ControlParameter Name="MailAdd1" ControlID="ctl00$ContentPlaceHolder1$DetailsView1$txtMailAdd1" Type="String" />
</UpdateParameters>