Datagrid row not added

Discussion in 'ASP .Net Datagrid Control' started by Vijay Kasi, Feb 19, 2004.

  1. Vijay Kasi

    Vijay Kasi Guest

    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
     
    Vijay Kasi, Feb 19, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Alvin Bruney [MVP], Mar 2, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig
    Replies:
    2
    Views:
    2,878
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Nov 2, 2004
  2. Bennett Haselton
    Replies:
    1
    Views:
    516
    John M Deal
    Nov 8, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    1
    Views:
    469
    Saravana
    Nov 22, 2004
  4. Replies:
    0
    Views:
    364
  5. D
    Replies:
    0
    Views:
    220
Loading...

Share This Page