Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid row not added

Reply
Thread Tools

Datagrid row not added

 
 
Vijay Kasi
Guest
Posts: n/a
 
      02-19-2004
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,N ULL,NULL)";
SqlConnection myConnection = new SqlConnection(ConnectionString2);
SqlCommand myCommand3 = new SqlCommand(CommandText3, myConnection);

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

thanks in advance
 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      03-02-2004
Your post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Vijay Kasi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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,N ULL,NULL)";
> SqlConnection myConnection = new SqlConnection(ConnectionString2);
> SqlCommand myCommand3 = new SqlCommand(CommandText3, myConnection);
>
> myConnection.Open();
> myCommand3.ExecuteNonQuery();
> myConnection.Close();
> BindGrid();
> }
>
> thanks in advance



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM
Add row under selectedindex row of datagrid ujjc001@gmail.com ASP .Net 0 12-15-2004 12:00 AM
How to add a new row to a datagrid with values of the selected row =?Utf-8?B?U3VyZXNo?= ASP .Net 1 11-22-2004 09:04 AM
Referencing Dataset row not Datagrid row Craig ASP .Net 2 11-02-2004 05:27 PM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 ASP .Net 2 06-06-2004 07:16 AM



Advertisments