TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhimanyu Singh
NA
116
48.9k
I am updating grid data by fetching it in textboxes through
Jan 9 2013 4:22 AM
Hello All,
any one can help me am new in this world
I am updating grid data by fetching it in textboxes through Dropdownlist1
I want when we select dropdownlist1's item then value will fetch in the textboxes so we can update it easily. Even it is updating well but its updating only after choosing all data in the textboxes and also image.
but i want single updation through textboxes but its not happening without selecting of all data including image also. Please help me
HTML Code :
<table style="margin-top:8px; float:left; width:450px; height:450px;">
<tr>
<td><p>Enter Hoarding ID:</p></td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="225px" Height="25px"> </asp:DropDownList>
</td>
<td></td>
<td class="style2"></td>
</tr>
<tr>
<td>
<p>
Hoarding Size:</p>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Height="23px" Width="220px"></asp:TextBox>
</td>
<td>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td>
<p>
Hoarding Landmark:</p>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Height="23px" MaxLength="50"
Width="220px"></asp:TextBox>
</td>
<td>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td>
Hoarding Cost:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Height="23px"
Width="220px"></asp:TextBox>
</td>
<td>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td>
Available From:</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Height="23px"
Width="220px"></asp:TextBox>
</td>
<td>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td>
Available To:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Height="23px"
Width="220px"></asp:TextBox>
</td>
<td>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td>
<p>
Choose Image:
</p>
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" ForeColor="#666666" Font-Names="Arial Narrow" />
<asp:Label ID="Label2" runat="server" ForeColor="Black" Text="Label"></asp:Label>
</td>
<td> </td>
<td class="style2"> </td>
</tr>
<tr>
<td>
</td>
<td>
<div style="margin-top:0px; width:100px; float:left; margin-right:0px;" >
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Update" BackColor="#EAEAEB" ForeColor="#994400" Height="27px" Width="65px" />
</div>
<p style="margin-top:0px; width:155px; color:#990000; float:left; margin-right:0px;" ><a href="ownerlogin_options.aspx">
<asp:Label ID="Label1" runat="server" Text="Post Hoarding Click Here.." style="float:left;" ForeColor="#990000" Visible="True"></asp:Label>
</a>
</p>
</td>
<td>
</td>
<td class="style2"></td>
</tr>
</table>
<div style="float:left; height:442px; width:451px; margin-top:15px; ">
<asp:ImageButton ID="ImageButton1" runat="server" style=" height:440px; width:449px; background-image:url(images/white_1.jpg);"/>
</div>
.CS code :
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//if (IsPostBack)
if (DropDownList1.SelectedItem.Text != "--select--")
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from providers_post where h_id = '" + DropDownList1.SelectedItem.Value + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
TextBox1.Text = dt.Rows[0][3].ToString();
TextBox2.Text = dt.Rows[0][6].ToString();
TextBox3.Text = dt.Rows[0][7].ToString();
TextBox4.Text = dt.Rows[0][9].ToString();
TextBox5.Text = dt.Rows[0][14].ToString();
ImageButton1.ImageUrl = dt.Rows[0][12].ToString();
Session["img"] = ImageButton1.ImageUrl;
Label2.Text = dt.Rows[0][12].ToString();
con.Close();
}
else
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
string i = DropDownList1.SelectedItem.Value;
if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentLength < 2097152) //actually it takes file size in byte so 2MB=2097152byte(1024*1024*2) and also put it in web configuration page under <System.Web>
{
try
{
string s = FileUpload1.PostedFile.ContentLength + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~\\") + "images\\" + "hoarding\\" + s);
Label2.Text = "images\\" + "hoarding\\" + s;
}
catch (Exception ex)
{
//Response.Write("<script>alert('Currently there is some error, Try again after some time.')</script>");
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("<script>alert('File size exceeds maximum limit 2 MB')</script>");
}
SqlCommand cmd = new SqlCommand("update providers_post set Size = '" + TextBox1.Text + "',Landmark = '" + TextBox2.Text + "',Cost = '" + TextBox3.Text + "', From_date = '" + TextBox4.Text + "', To_date='" + TextBox5.Text + "', hoarding_image='" + Label2.Text + "' where h_id = '" + i + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
con.Close();
Response.Redirect("hoarding_edit.aspx");
//Response.Write("<script>alert('Details updated successfully')</script>");
}
}
Reply
Answers (
0
)
How to edit the rows when the chkbox is selected?
How to get the combobox value to another form....