Retrieving value from textbox in a Gridview
Hey pple. i am facing a problem now whereby i could not retrieve value from a textbox in a gridview. I want it to be store in a database in the future. Now i need to identify the existence of a textbox first, before i could actually store the value in the textbox.
The problem that i am facing now is actually because, my textbox is declare inside a gridview, hence it is not detectable/declare in the aspx form.
Textbox name : Notestxtbox
CS CODE
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
GridViewRow row = this.GridView1.Rows[this.GridView1.EditIndex];
TextBox LastName = (TextBox)row.Cells[2].FindControl("Notestxtbox");
UpdateIDlbl.Visible = false;
Emaillbl.Visible = false;
Textinput.Visible = false;
string strConString = ConfigurationManager.ConnectionStrings["SocialSystemConnectionString"].ConnectionString;
SqlConnection con = newSqlConnection(strConString);
SqlCommand cmd = newSqlCommand("SELECT UpdateID FROM [Update]", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
UpdateIDlbl.Text = reader["UpdateID"].ToString();
}
reader.Close();
con.Close();
GridView1.Visible = false;
}
SourceCode:
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"BorderStyle="None"Height="0px"Width="355px"GridLines="None">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("FullName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<ahref=""><asp:LabelID="Label1"runat="server"Text='<%# Bind("FullName") %>'></asp:Label></a> wrote a note.<br/><br/>
<asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label><br/><br/><asp:TextBoxID="TextBox2"runat="server"Height="44px"Width="292px"Visible="false"></asp:TextBox>
<asp:TextBoxID="Notestxtbox"runat="server"Columns="36"TextMode="MultiLine"MaxLength="100"Height="60px"Width="304px"></asp:TextBox>
&n bsp; &nbs p;
&n bsp; &nbs p;
&n bsp;  <asp:ButtonID="NoteComment"runat="server"OnClick="NoteComment_Click"Text="Comment"/> <br/><br/>
</ItemTemplate>
</asp:TemplateField></Columns>
</asp:GridView>
Last edited by julius; March 12th, 2009 at 03:31 AM..
|