Click here to Skip to main content
15,929,356 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: XML navigation Pin
SeMartens16-Feb-09 2:42
SeMartens16-Feb-09 2:42 
Questionscroll posititon for div but different problem (timer is there) Pin
rahul_miche15-Feb-09 23:01
rahul_miche15-Feb-09 23:01 
AnswerRe: scroll posititon for div but different problem (timer is there) Pin
Gaurav K Singh16-Feb-09 3:28
Gaurav K Singh16-Feb-09 3:28 
GeneralRe: scroll posititon for div but different problem (timer is there) Pin
rahul_miche16-Feb-09 23:18
rahul_miche16-Feb-09 23:18 
GeneralRe: scroll posititon for div but different problem (timer is there) Pin
Gaurav K Singh16-Feb-09 23:23
Gaurav K Singh16-Feb-09 23:23 
GeneralRe: scroll posititon for div but different problem (timer is there) Pin
rahul_miche16-Feb-09 23:42
rahul_miche16-Feb-09 23:42 
GeneralRe: scroll posititon for div but different problem (timer is there) Pin
rahul_miche17-Feb-09 0:10
rahul_miche17-Feb-09 0:10 
QuestionUpdate the table based on selected gridview row Pin
Shanthi Diana15-Feb-09 22:40
Shanthi Diana15-Feb-09 22:40 
hi All,

I am new to dot net...

i am learning it and I am doing my masters project in c# dot net with sql server 2000 backend...

The issue i am having now is...
i am having a gridview, upon selection of one of the rows, the row data is loaded into the textbox and dropdowns, so that when changes are made and update button is hit, the data is updated in the backend...

all works fine except for the update Frown | :( issue is with postback but i dont know how to do that... pls help... giving all the codes below...

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class scenarios : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("...;");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter da;
common obj = new common();
string sql;
string s;

protected void Page_Load(object sender, EventArgs e)
{
Session["projid"] = "12345";
Session["projname"] = "ProjectA";
if (!IsPostBack)
{
pid.Text = Session["projid"].ToString();
pname.Text = Session["projname"].ToString();
sql = "select * from scenarios where pid = '" + Session["projid"].ToString() + "'";
da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
da.Fill(dt);
int prowct = dt.Rows.Count;
if (prowct == 0)
{
btnadd.Visible = true;
btnupdate.Visible = false;
GridView1.DataBind();
}
else
{
btnadd.Visible = true;
btnupdate.Visible = false;
GridView1.DataBind();
}


}

}
protected void btnadd_Click(object sender, EventArgs e)
{
con.Open();
sql = "Insert into scenarios values ('" + pid.Text + "','" + pname.Text + "','" + tbcat.Text + "','" + tbscenario.Text + "','" + ddlprob.SelectedValue.ToString() + "','" + ddlprob.SelectedItem.Text + "','" + ddlimpact.SelectedValue.ToString() + "','" + ddlimpact.SelectedItem.Text + "','" + tbmitig.Text + "')";
cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
obj.msgbox("Values are inserted");
con.Close();
clearall();
GridView1.DataBind();

}

public void clearall()
{
tbcat.Text = "";
tbscenario.Text = "";
ddlprob.ClearSelection();
ddlimpact.ClearSelection();
tbmitig.Text = "";
}
protected void btnreset_Click(object sender, EventArgs e)
{
clearall();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
btnadd.Visible = false;
btnupdate.Visible = true;
s = GridView1.SelectedValue.ToString();
sql = "select * from scenarios where ID = '" + s + "'";
con.Open();
cmd = new SqlCommand(sql, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
tbcat.Text = dr[3].ToString();
tbscenario.Text = dr[4].ToString();
ddlprob.SelectedIndex = int.Parse(dr[5].ToString());
ddlimpact.SelectedIndex = int.Parse(dr[7].ToString());
tbmitig.Text = dr[9].ToString();
}
con.Close();

}
protected void btnupdate_Click(object sender, EventArgs e)
{
//cmd.Connection = con;
con.Open();
sql = "update scenarios set discateg = '" + tbcat.Text + "', disscenario= '" + tbscenario.Text + "', probval = '" + ddlprob.SelectedValue.ToString() + "', prob = '" + ddlprob.SelectedItem.Text + "', impactval = '" +ddlimpact.SelectedValue.ToString() + "', impact = '" + ddlimpact.SelectedItem.Text + "', mitig = '" + tbmitig.Text + "' where ID= '" +s + "'";
cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
obj.msgbox("Values are updated");
con.Close();
clearall();
GridView1.DataBind();

}
}
-----------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="scenarios.aspx.cs" Inherits="scenarios" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
text-align: right;
}
</style>
</head>
<body style="font-family: Verdana; font-size: x-small">
<form id="form1" runat="server">
<div>

<table class="style1">
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Project Name:</td>
<td>
<asp:Label ID="pname" runat="server"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
<br />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Project ID:</td>
<td>
<asp:Label ID="pid" runat="server"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Category:</td>
<td>
<asp:TextBox ID="tbcat" runat="server" Width="183px" Font-Names="Verdana"
Font-Size="X-Small"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Disaster Scenario:</td>
<td>
<asp:TextBox ID="tbscenario" runat="server" Height="62px" Width="183px"
Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Probability:</td>
<td>
<asp:DropDownList ID="ddlprob" runat="server" Font-Names="Verdana"
Font-Size="X-Small">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">Low</asp:ListItem>
<asp:ListItem Value="2">Medium</asp:ListItem>
<asp:ListItem Value="3">High</asp:ListItem>
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Impact:</td>
<td>
<asp:DropDownList ID="ddlimpact" runat="server" Font-Names="Verdana"
Font-Size="X-Small">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">High</asp:ListItem>
<asp:ListItem Value="2">Medium</asp:ListItem>
<asp:ListItem Value="3">Low</asp:ListItem>
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
Mitigation:</td>
<td>
<asp:TextBox ID="tbmitig" runat="server" Height="62px" Width="183px"
Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2">
<asp:Button ID="btnupdate" runat="server" Height="20px"
onclick="btnupdate_Click" Text="Update" Width="50px" />
<asp:Button ID="btnadd" runat="server" Height="20px" Text="Add" Width="50px"
onclick="btnadd_Click" />
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;
<asp:Button ID="btnreset" runat="server" Height="20px" Text="Reset"
Width="50px" onclick="btnreset_Click" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td class="style2" colspan="2">
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" DataKeyNames="ID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexCha nged"
style="text-align: left">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:bcpertConnectionString %>"
SelectCommand="SELECT * FROM [scenarios] WHERE ([pid] = @pid)">
<SelectParameters>
<asp:SessionParameter Name="pid" SessionField="projid" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>
------------------------

table creation code:
CREATE TABLE [dbo].[scenarios] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[pid] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[pname] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[discateg] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[disscenario] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[prob] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[impact] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[mitig] [varchar] (300) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
AnswerRe: Update the table based on selected gridview row Pin
keyur satyadev15-Feb-09 23:16
keyur satyadev15-Feb-09 23:16 
QuestionHow to access the contain of master page in our cs file? Pin
keyur satyadev15-Feb-09 22:29
keyur satyadev15-Feb-09 22:29 
AnswerRe: How to access the contain of master page in our cs file? Pin
butchzn15-Feb-09 22:51
butchzn15-Feb-09 22:51 
GeneralRe: How to access the contain of master page in our cs file? Pin
keyur satyadev15-Feb-09 23:17
keyur satyadev15-Feb-09 23:17 
GeneralRe: How to access the contain of master page in our cs file? Pin
raju melveetilpurayil16-Feb-09 0:32
professionalraju melveetilpurayil16-Feb-09 0:32 
Questionms outlook 2003 + address list + windows application Pin
bhavna432115-Feb-09 21:43
bhavna432115-Feb-09 21:43 
QuestionNullReferenceException in UserControl in GridView Pin
sdas00715-Feb-09 21:42
sdas00715-Feb-09 21:42 
AnswerRe: NullReferenceException in UserControl in GridView Pin
Calin Tatar15-Feb-09 23:55
Calin Tatar15-Feb-09 23:55 
GeneralRe: NullReferenceException in UserControl in GridView Pin
sdas00717-Feb-09 19:06
sdas00717-Feb-09 19:06 
QuestionEntering javascript blocks into TextBox Pin
AndyBrew7015-Feb-09 21:17
AndyBrew7015-Feb-09 21:17 
AnswerRe: Entering javascript blocks into TextBox Pin
AndyBrew7015-Feb-09 21:33
AndyBrew7015-Feb-09 21:33 
AnswerRe: Entering javascript blocks into TextBox Pin
AndyBrew7016-Feb-09 0:11
AndyBrew7016-Feb-09 0:11 
Questioncheck boxes [modified] Pin
JAYRAJ GIRI15-Feb-09 20:14
JAYRAJ GIRI15-Feb-09 20:14 
AnswerRe: check boxes Pin
Christian Graus15-Feb-09 20:19
protectorChristian Graus15-Feb-09 20:19 
AnswerRe: check boxes Pin
Christian Graus16-Feb-09 10:00
protectorChristian Graus16-Feb-09 10:00 
Question[Message Deleted] Pin
chandhuBTS15-Feb-09 19:28
chandhuBTS15-Feb-09 19:28 
AnswerRe: Unhandled Exception Pin
Christian Graus15-Feb-09 19:41
protectorChristian Graus15-Feb-09 19:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.