Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with: Add New record in GridView 1

Status
Not open for further replies.

neegottlob

Programmer
Mar 26, 2006
22
BG
Hello,
First of all that might be kind of a stupid question but I really need it:). Here it is-->I have tried to insert new record in gridview but when I click on the "NEW" - link button, I just do nothing. So i've looked all arround and didn't find something that can help me. All the help code is using Code Behind and bind() the gridView. Actually I would like to make it as least code behind as I can. Any advice? Here is the "source":

Code:
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProdID"
        DataMember="DefaultView" DataSourceID="AccessDataSource1" HorizontalAlign="Center" AllowPaging="True" AllowSorting="True" TabIndex="3" BackColor="Transparent" Caption="????? - ????????" OnRowUpdated="GridView2_RowUpdated" OnRowDeleted="GridView2_RowDeleted">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True"
                ShowInsertButton="True" />
            <asp:BoundField DataField="ImeProd" HeaderText="ImeProd" SortExpression="ImeProd" />
            <asp:BoundField DataField="Cena" HeaderText="Cena" SortExpression="Cena" />
            <asp:ImageField DataAlternateTextField="SnimkaProd" dataimageurlformatstring="/website3/images/Products/{0}.jpg" DataAlternateTextFormatString="snimka na: {0}"
                DataImageUrlField="SnimkaProd" HeaderText="Image" NullDisplayText="Empty">
            </asp:ImageField>
            <asp:TemplateField HeaderText="Upload File" ShowHeader="False" Visible="False">
    <EditItemTemplate>
        <input id="MyFile" type="file" runat="server" />
    </EditItemTemplate>
    
</asp:TemplateField>
        </Columns>
    </asp:GridView>


and this is the AccessDAtaSource:

Code:
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Li4niDanni.mdb"
        SelectCommand="SELECT SnimkaProd, ProdID, ImeProd, Cena, CategorID FROM Produkti WHERE ([CategorID] = @CatIDSelected)"
        UpdateCommand="UPDATE [Produkti] SET [SnimkaProd] = @SnimkaProd, [ImeProd] = @ImeProd, [Cena] = @Cena WHERE ProdID=@ProdID"
        InsertCommand="INSERT INTO [Produkti] (ProdID, ImeProd, Cena, SnimkaProd) VALUES (@ProdID, @ImeProd, @Cena, @SnimkaProd)"
        DeleteCommand="DELETE FROM [Produkti] WHERE [ProdID] = @ProdID">
        <SelectParameters>
        <asp:ControlParameter ControlID="GridView3" Name="CatIDSelected" PropertyName="SelectedValue"/>
        </SelectParameters>
        <DeleteParameters>
           <asp:Parameter Name="ProdID" Type="String" />
        </DeleteParameters>
        <InsertParameters>
              <asp:Parameter Name="SnimkaProd" Type="String" />
              <asp:Parameter Name="Cena" Type="String" />
              <asp:Parameter Name="ImeProd" Type="String" />
              <asp:Parameter Name="ProdID" Type="String" />
        </InsertParameters>
        <UpdateParameters>
              <asp:Parameter Name="SnimkaProd" Type="String" />
              <asp:Parameter Name="ImeProd" Type="String" />
              <asp:Parameter Name="Cena" Type="String" />
              <asp:Parameter Name="ProdID" Type="String" />
        </UpdateParameters>
        </asp:AccessDataSource>

Thanks You,
G. Kalchev
 
G. Kalchev - the fact that nothing happens with the Insert button brings that issue in the forefront IMO -- I haven't switched over to GridView yet (soon) but I would venture to say a search using Google and Google Groups, date restrictive, with a couple of good string "Gridview Insert asp.net" you should find many examples of code. Give that a shot - I can't stay to evaluate at the moment but like I said, I look closely at the functioning of the Insert button and move out from there.
 
Thank you:)
If somebody accidently comes to that question the answer is: It was hard to believe that gridview doesn't have own way to add new record so I had to use dataview or formview or whatever that can be called from:
Code:
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
        If (e.CommandName = "New") Then
            Refresh1()
            DetailsView1.Visible = True
            DetailsView1.ChangeMode(DetailsViewMode.Insert)

        End If

    End Sub

and be carefull to take care for details view - DetailsView3.ChangeMode(DetailsViewMode.ReadOnly)
because when you finish insert it will stay in insert mode.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top