Click here to Skip to main content
16,011,120 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: HTML Tag rendering Pin
dews turner16-Jul-08 5:05
dews turner16-Jul-08 5:05 
GeneralRe: HTML Tag rendering Pin
Imran Khan Pathan16-Jul-08 20:06
Imran Khan Pathan16-Jul-08 20:06 
Questionsocket exception for simple email validation code Pin
Lengdor16-Jul-08 1:22
Lengdor16-Jul-08 1:22 
Questiondrag drop lists Pin
ajaaya16-Jul-08 1:02
ajaaya16-Jul-08 1:02 
AnswerRe: drag drop lists Pin
eyeseetee16-Jul-08 1:15
eyeseetee16-Jul-08 1:15 
GeneralRe: drag drop lists Pin
eyeseetee16-Jul-08 4:01
eyeseetee16-Jul-08 4:01 
Questioncustom Template databound control in asp.net 2.0 Pin
Member 392066716-Jul-08 0:44
Member 392066716-Jul-08 0:44 
Generalupdate gridview ----help pls Pin
merinkmathew16-Jul-08 0:22
merinkmathew16-Jul-08 0:22 
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataKeyNames="Productid" ShowFooter ="True"
ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />

<Columns >

<asp:TemplateField HeaderText ="Productid" InsertVisible ="False" SortExpression ="Productid" >
<ItemTemplate >
<asp:Label ID="lblProductid" runat ="server" Text='<%# Eval("Productid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText ="ProductCode" SortExpression ="ProductCode" InsertVisible ="False" >
<EditItemTemplate >

<asp:TextBox ID ="txtProductCode" runat ="server" Text ='<%#Bind("ProductCode") %>'></asp:TextBox>

</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblProductCode" runat ="server" Text='<%#Eval("ProductCode") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate >
<asp:TextBox ID="txtfooterProductCode" runat="server" > </asp:TextBox>
<asp:RequiredFieldValidator ID="rfvProductCode" runat="server" ControlToValidate="txtfooterProductCode" ErrorMessage="*"></asp:RequiredFieldValidator>

</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText ="ProductName" InsertVisible ="False" SortExpression ="ProductName">
<EditItemTemplate >
<asp:TextBox ID="txtProductName" runat ="server" Text='<%#Bind("ProductName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate >
<asp:Label ID ="lblProductName" runat ="server" Text='<%#Eval("ProductName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfooterProductName" runat="server" > </asp:TextBox>
<asp:RequiredFieldValidator ID="rfvProductName" runat="server" ControlToValidate="txtfooterProductName" ErrorMessage="*"></asp:RequiredFieldValidator>


</FooterTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText ="ProductDescription" InsertVisible ="False" SortExpression ="ProductDescription">
<EditItemTemplate >
<asp:TextBox ID="txtProductDescription" runat ="server" Text ='<%#Bind("ProductDescription") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate >

<asp:Label ID ="lblProductDescription" runat ="server" Text ='<%# Eval("ProductDescription") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate >
<asp:TextBox ID="txtProductDescription" runat ="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvProductDescription" runat="server" ControlToValidate="txtProductDescription" ErrorMessage="*"></asp:RequiredFieldValidator>


</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="EditRecord">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>

<asp:LinkButton ID="lnkInsert" runat="server" Text ="Insert" OnClick="lnkInsert_Click"></asp:LinkButton>
</FooterTemplate>

</asp:TemplateField>

</Columns>



</asp:GridView>

<asp:Label ID="lblMessage" runat="server" Text ="Insert Record Successfully" Visible ="false" > </asp:Label>

</div>
</form>



code behind

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;

public partial class HOMEME_AddRowGrid : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Binddata();
}

}

public void Binddata()
{



string sqlQuery = "SELECT * from Product";
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, conn);
DataTable dtData = new DataTable();
sda.Fill(dtData);

GridView1.DataSource = dtData.DefaultView;
GridView1.DataBind();
}

protected void lnkInsert_Click(object sender, EventArgs e)
{

TextBox txtfooterProductCode = GridView1.FindControl("txtfooterProductCode") as TextBox;
TextBox txtfooterProductName = GridView1.FindControl("txtfooterProductName") as TextBox;
TextBox txtProductDescription = GridView1.FindControl("txtProductDescription") as TextBox;

SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
conn.Open();
cmd = new SqlCommand("InsertProduct", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@ProductCode", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtfooterProductCode")).Text;
cmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtfooterProductName")).Text;
cmd.Parameters.Add("@ProductDescription", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtProductDescription")).Text;
cmd.ExecuteNonQuery();
conn.Close();
Binddata();


}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{

}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//int Productid = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblProductid").Text);
// TextBox txtProductCode = GridView1.FindControl("txtProductCode") as TextBox;
// TextBox txtProductName = GridView1.FindControl("txtProductName") as TextBox;
// TextBox txtProductDescription = GridView1.FindControl("txtProductDescription") as TextBox;

// SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
// conn.Open();
// cmd = new SqlCommand("UpdateProduct", conn);
// cmd.CommandType = CommandType.StoredProcedure;

// //cmd.Parameters.AddWithValue("Productid", SqlDbType.VarChar).Value
// cmd.Parameters.AddWithValue("Productid", GridView1.DataKeys["Productid"]);
// cmd.Parameters.Add("@ProductCode", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtProductCode")).Text;
// cmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtProductName")).Text;
// cmd.Parameters.Add("@ProductDescription", SqlDbType.VarChar).Value = ((TextBox)GridView1.FooterRow.FindControl("txtProductDescription")).Text;
// cmd.ExecuteNonQuery();
// conn.Close();
// Binddata();

}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{

}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{

}
}






help-- how we update delete in gridview using storeporocedure




CREATE PROCEDURE [UpdateProduct]


@ProductCode VARCHAR(50),
@productName VARCHAR(50),
@ProductDescription VARCHAR(500),
@Productid numeric


AS
update Product set ProductCode=@ProductCode,productName =@productName,ProductDescription =@ProductDescription where Productid=@Productid
GO

pls sent code to my id
GeneralRe: update gridview ----help pls Pin
Herman<T>.Instance16-Jul-08 1:55
Herman<T>.Instance16-Jul-08 1:55 
GeneralRe: update gridview ----help pls Pin
merinkmathew16-Jul-08 4:09
merinkmathew16-Jul-08 4:09 
GeneralRe: update gridview ----help pls Pin
Herman<T>.Instance16-Jul-08 6:05
Herman<T>.Instance16-Jul-08 6:05 
QuestionProblem in accessing Runtime Controls Pin
nagendrathecoder16-Jul-08 0:10
nagendrathecoder16-Jul-08 0:10 
AnswerRe: Problem in accessing Runtime Controls [modified] Pin
Imran Khan Pathan16-Jul-08 0:47
Imran Khan Pathan16-Jul-08 0:47 
QuestionASP.NET Caching [modified] Pin
10215-Jul-08 23:52
10215-Jul-08 23:52 
AnswerRe: ASP.NET Caching Pin
Sathesh Sakthivel15-Jul-08 23:55
Sathesh Sakthivel15-Jul-08 23:55 
AnswerRe: ASP.NET Caching Pin
eyeseetee16-Jul-08 0:28
eyeseetee16-Jul-08 0:28 
AnswerRe: ASP.NET Caching Pin
sumit703416-Jul-08 0:30
sumit703416-Jul-08 0:30 
Questionpaging doesnt work in update panel Pin
eyeseetee15-Jul-08 23:45
eyeseetee15-Jul-08 23:45 
AnswerRe: paging doesnt work in update panel Pin
Venkatesh Mookkan15-Jul-08 23:48
Venkatesh Mookkan15-Jul-08 23:48 
GeneralRe: paging doesnt work in update panel Pin
eyeseetee16-Jul-08 0:01
eyeseetee16-Jul-08 0:01 
QuestionGridView Pin
Assaf8215-Jul-08 23:36
Assaf8215-Jul-08 23:36 
AnswerRe: GridView Pin
Venkatesh Mookkan15-Jul-08 23:50
Venkatesh Mookkan15-Jul-08 23:50 
GeneralRe: GridView Pin
Assaf8215-Jul-08 23:53
Assaf8215-Jul-08 23:53 
GeneralRe: GridView Pin
Assaf8216-Jul-08 0:00
Assaf8216-Jul-08 0:00 
AnswerRe: GridView Pin
sumit703415-Jul-08 23:52
sumit703415-Jul-08 23:52 

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.