Datagrid row not added

V

Vijay Kasi

Hi All,

i am trying to add a row in a datagrid ( am a newbie). I religiously
followed http://aspnet.4guysfromrolla.com/articles/021203-1.aspx
article, still not able to get the result.

I see that the when a button is clicked, the ItemCommand is not being
activated. i am posting part of the code

from .aspx file

<asp:datagrid id="myDataGrid" runat="server" AutoGenerateColumns="False"
ForeColor="Black" Font-Names="Verdana"
Font-Size="Smaller" PageSize="3" CellPadding="4"
BackColor="White" ShowFooter="True" BorderWidth="1px"
BorderStyle="None" BorderColor="#3366CC">
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99"
BackColor="#009999"></SelectedItemStyle>
<EditItemStyle Font-Names="Arial Rounded MT Bold"
HorizontalAlign="Center" VerticalAlign="Middle"></EditItemStyle>
<ItemStyle ForeColor="Black" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"
ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<FooterStyle Font-Size="Larger" ForeColor="#003399"
BackColor="#003399"></FooterStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399"
BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
<Columns>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate>
<asp:Label id=Label3 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.title") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label id="Label4" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.description") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="Textbox4" Columns="60"
runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button Text="comment" Runat="server" ID="btnComment" />
</ItemTemplate>
<FooterTemplate>
<asp:Button Text="add" Runat="server" ID="btnAdd"
CommandName="insertSetUp" />
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

******************************************************************

..aspx.cs file


public void myDataGrid_ItemCommand(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Message.Text="in item command";

TextBox t1= (TextBox)e.Item.FindControl("textbox2");
TextBox t2= (TextBox)e.Item.FindControl("textbox4");
string ConnectionString2 = "Network Library=DBMSSOCN;Data
Source=db1\\PROD;Initial Catalog=Delphi;User
ID=delphiwebuser;Password=Enter!";
string CommandText3 = "INSERT into Barrier values
(17,'@t1.Text','@t2.Text','SetUp',NULL,NULL,NULL,NULL,NULL)";
SqlConnection myConnection = new SqlConnection(ConnectionString2);
SqlCommand myCommand3 = new SqlCommand(CommandText3, myConnection);

myConnection.Open();
myCommand3.ExecuteNonQuery();
myConnection.Close();
BindGrid();
}

thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top