Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i gave a textbox and button in list view want to insert textbox's where id=@id value in one column, but textbox's value in not saving in database from listview. if i m giving that textbox out of list view then data is saving and updating in database but from listview not working, and when i chnage textbox's id den object refrence null show..
Posted
Updated 3-Sep-14 21:45pm
v2
Comments
George Jonsson 4-Sep-14 1:19am    
Sorry, but your question is very difficult to understand.
Can you please rephrase and maybe add some code example.
Aarti Yadav 4-Sep-14 1:23am    
this my design


<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"

>
<alternatingitemtemplate><br>
<div class="name">
<span>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' CssClass="fixd" />
<br />
<br />
<asp:Label ID="messageLabel" runat="server" Text='<%# Eval("message") %>' />
<br />

<br />


<br />

<asp:Label ID="task_statusLabel" runat="server"
Text='<%# Eval("task_status") %>' />


<br />
Posted by :
<asp:Label ID="asigntask_nameLabel" runat="server"
Text='<%# Eval("asigntask_name") %>' CssClass="fixd" />



<span class="asgndate">date
<asp:Label ID="curnt_dateLabel" runat="server"
Text='<%# Eval("curnt_date") %>' /></span>

<div class="cust_summary">Replay</div>

<div id="cust_details" class="cust_details" style="display:none; ">Hello Replay here !
<br />

<asp:TextBox ID="TextBoxL" placeholder="Write Your Comment.." class="blog" runat="server" TextMode="MultiLine" Rows="2"><br /> <br />
<asp:Button ID="Button3" runat="server" Text="Post" onclick="Button3_Click" /> </div> <br />

</span></div>



<edititemtemplate>
<div class="name">
<span style="">

<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' CssClass="name fixd" />
<br />
<asp:TextBox ID="messageTextBox" runat="server" Text='<%# Bind("message") %>' />
<br />
<br />

<br />
<asp:TextBox ID="task_statusTextBox" runat="server"
Text='<%# Bind("task_status") %>' />
<br /><br />
<span class="msgcolor"> Posted by</span>
<asp:TextBox ID="asigntask_nameTextBox" runat="server"
Text='<%# Bind("asigntask_name") %>' />



<asp:TextBox ID="curnt_dateTextBox" runat="server"
Text='<%# Bind("curnt_date") %>' />
<br />

<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<br />
<br />
</span></div>

<emptydatatemplate>


<span>No data was returned.</span>

<insertitemtemplate><br>
<div class="name">
<span style="" class="name">

<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' CssClass="name fixd" />
<br />
<asp:TextBox ID="messageTextBox" runat="server" Text='<%# Bind("message") %>' />
<br />
<br />

<br />
<asp:TextBox ID="task_statusTextBox" runat="server"
Text='<%# Bind("task_status") %>' />
<br />



<br />
<span class="msgcolor"> Posted by</span>
<asp:TextBox ID="asigntask_nameTextBox" runat="server"
Text='<%# Bind("asigntask_name") %>' />

<asp:TextBox ID="
Aarti Yadav 4-Sep-14 1:24am    
this is a back code
protected void Button3_Click(object sender, EventArgs e)
{
try
{
SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

SqlCommand cmd = new SqlCommand();

cmd.Connection = c; //assigning connection to command
cmd.CommandType = CommandType.Text; //representing type of command

cmd.CommandText ="update task set post=@post where asigntask_name=@asigntask_name";


cmd.Parameters.AddWithValue("@post", TextBoxL.text);
cmd.Parameters.AddWithValue("@asigntask_name", s2);
c.Open();
cmd.ExecuteNonQuery();
c.Close();
TextBoxL.Text = "";
this.Response.Redirect("cnnn.aspx");
}
catch (System.Data.SqlClient.SqlException ex)
{
Label1.Text = ex.Message.ToString();
}
}
George Jonsson 4-Sep-14 1:29am    
Please do not add code in a comment.
There is an 'Improve Question' widget you can use for this.
Nandakishore G N 4-Sep-14 2:41am    
You cannot get TextBox1 Instance, Since it is inside listview. View this link

http://stackoverflow.com/questions/11611291/how-i-use-the-itemcommand-event-for-my-listview-in-my-asp-net-application

and change or write the update inside the listview_itemcommand event.
(Note:- Don't prefer Inline queries, Instead use Stored Procedures)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900