I want to select value in a gridview control of current row

Hi Gurus,

Dear I have just started .net asp 2.0 with Web Developer Express edition no previous background of .net.

I have a table accessories with 10 columns in it and I am show only two in gridview (tabular form) i add a button control which is not bound to any data item in table.

What I want that when user click on that button another form should popup and user could do operations like add, edit, delete there. Fot that purpose i need to get the value of primary key of current row. I search in already available solutions and found a way to do it which is

 Session["ww"] = GridView1.SelectedRow.Cells[0].Text;

but when i run this line system give an error because no row is selected so SelectedRow is set to null in debug window.

I dont know that how i can make this row selected which is my current row already.

and the following method is call on that row on click event as:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
           
        Session["ww"] = GridView1.SelectedRow.Cells[0].Text; --- Error generate on this row.
       
        Response.Redirect("AccessoriesDetails.aspx");
    }

Folowing is the error detail :



System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_0eqixp6p"
  StackTrace:
       at ASP.accessories_aspx.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in c:\Documents and Settings\Owner.HOME\My Documents\Visual Studio 2005\WebSites\MicroHardOnline\Accessories.aspx:line 29
       at System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e)
       at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
       at System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Please Advice.
MateenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ptleitchCommented:
you need to use detailsview or formview in conjunction with the gridview.  enable selection in the gridview tasks panel.  You need to use a separate data source for each control and filter the data source for the detailsview or formview by the primary key of the gridview. to reflect the changes in the two controls you will need to add detailsview1.databind() to all of the inserting deleting editing events of gridview and gridview1.databind() to all of those events in detailsview.  I could probably be more specific if i had more information.
0
MateenAuthor Commented:
Thankyou very much for your reply my dear friend I could not see the comment in couple of day since i was busy in some other thing but i have figure it out that what was happening actually as i said i am new to this technology i was writing the code at wrong event trigger i should write it to IndexChanged event so the object gridview or formview will not return a null reference but where i was using it in that context the object wasnt available so it was not finding it.

Thanks again. I appreciate the effort and time you put into it.

Now I need your help in the following senario if u please:

Master Table
NetID (PK)
NetName

Detail Table
NetID (FK)+Composite(PK)
TarID Composite(PK)

Let me give u what I have done then I'll tell u where i am stucking

<%@ Page Language="C#" MasterPageFile="~/MainPage.master" Title="Untitled Page" %>

<script runat="server">
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
      DropDownList NetworkDDL = (DropDownList)FormView1.FindControl("DropDownList1");
      FormView1.PageIndex = NetworkDDL.SelectedIndex;
    }
    protected void FormView2_ModeChanged(object sender, EventArgs e)
    {
        if (FormView2.CurrentMode == FormViewMode.Insert)
        {
            DropDownList f = (DropDownList)FormView1.FindControl("DropDownList1");
        }
    }

    protected void NewButton_Click(object sender, EventArgs e)
    {
        Label l = (Label)FormView2.NamingContainer.FindControl("NETIDlabel");
        l.Text = (String)FormView1.SelectedValue;        
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="WebFormArea" Runat="Server">
    &nbsp; &nbsp;&nbsp;&nbsp;
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="NETID" DataSourceID="NetworkDS"
        Style="z-index: 100; left: 203px; position: absolute; top: 140px" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Height="225px" Width="349px">
        <EditItemTemplate>
            <asp:Label ID="NETIDLabel1" runat="server" Text='<%# Eval("NETID") %>' style="z-index: 100; left: 157px; position: absolute; top: 107px" TabIndex="1"></asp:Label><br />
            <asp:TextBox ID="PICTUREPATHTextBox" runat="server" Text='<%# Bind("PICTUREPATH") %>' style="z-index: 101; left: 157px; position: absolute; top: 174px" TabIndex="3"></asp:TextBox><br />
            <asp:TextBox ID="NETNAMETextBox" runat="server" Text='<%# Bind("NETNAME") %>' style="z-index: 102; left: 157px; position: absolute; top: 139px" TabIndex="2"></asp:TextBox>
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 99; left: 49px; position: absolute; top: 54px" Text="Network Setup"></asp:Label>
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update" style="z-index: 104; left: 211px; position: absolute; top: 211px" TabIndex="4"></asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" style="z-index: 105; left: 266px; position: absolute; top: 211px" TabIndex="5"></asp:LinkButton>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 106; left: 48px; position: absolute; top: 53px" Text="Network Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 107; left: 44px; position: absolute;
                top: 104px" Text="ID"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 108; left: 45px; position: absolute;
                top: 144px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 109; left: 42px; position: absolute;
                top: 177px" Text="Image URL:"></asp:Label>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="NETIDTextBox" runat="server" Text='<%# Bind("NETID") %>' style="z-index: 100; left: 154px; position: absolute; top: 101px">
            </asp:TextBox><br />
            <asp:TextBox ID="PICTUREPATHTextBox" runat="server" Text='<%# Bind("PICTUREPATH") %>' style="z-index: 101; left: 154px; position: absolute; top: 182px">
            </asp:TextBox><br />
            <asp:TextBox ID="NETNAMETextBox" runat="server" Text='<%# Bind("NETNAME") %>' style="z-index: 102; left: 154px; position: absolute; top: 141px">
            </asp:TextBox><br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" style="z-index: 103; left: 225px; position: absolute; top: 216px">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" style="z-index: 104; left: 267px; position: absolute; top: 216px">
            </asp:LinkButton>
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 105; left: 36px; position: absolute; top: 57px" Text="Network Setup"></asp:Label>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 106; left: 37px; position: absolute; top: 58px" Text="Network Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 107; left: 37px; position: absolute;
                top: 104px" Text="ID"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 108; left: 37px; position: absolute;
                top: 144px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 110; left: 37px; position: absolute;
                top: 184px" Text="Image URL:"></asp:Label>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="NETIDLabel" runat="server" Text='<%# Eval("NETID") %>' style="z-index: 100; left: 166px; position: absolute; top: 102px" TabIndex="1"></asp:Label><br />
            <asp:Label ID="PICTUREPATHLabel" runat="server" Text='<%# Bind("PICTUREPATH") %>' style="z-index: 101; left: 166px; position: absolute; top: 172px" TabIndex="3"></asp:Label>
            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="NetworkDS" DataTextField="NETNAME"
                DataValueField="NETID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                Style="z-index: 112; left: 198px; position: absolute; top: 101px" AutoPostBack="True" SelectedIndex="<%# FormView1.PageIndex %>" Width="121px">
            </asp:DropDownList>
            <br />
            <asp:Label ID="NETNAMELabel" runat="server" Text='<%# Bind("NETNAME") %>' style="z-index: 103; left: 166px; position: absolute; top: 137px" TabIndex="2"></asp:Label><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit" style="z-index: 104; left: 200px; position: absolute; top: 197px" TabIndex="5"></asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Delete" style="z-index: 105; left: 275px; position: absolute; top: 197px" TabIndex="6"></asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New" style="z-index: 106; left: 166px; position: absolute; top: 197px" TabIndex="4"></asp:LinkButton>
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 107; left: 43px; position: absolute; top: 56px" Text="Network Setup"></asp:Label>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 108; left: 45px; position: absolute; top: 57px" Text="Network Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 109; left: 44px; position: absolute;
                top: 102px" Text="ID"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 110; left: 44px; position: absolute;
                top: 137px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 111; left: 44px; position: absolute;
                top: 172px" Text="Image URL:"></asp:Label>
        </ItemTemplate>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
    </asp:FormView>
    <asp:SqlDataSource ID="NetworkDS" runat="server" ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:WebPortal-New %>"
        ProviderName="<%$ ConnectionStrings:WebPortal-New.ProviderName %>"
        OldValuesParameterFormatString="original_{0}"
        DeleteCommand='DELETE FROM "NETWORKS" WHERE "NETID" = :original_NETID AND "PICTUREPATH" = :original_PICTUREPATH AND "NETNAME" = :original_NETNAME'
        InsertCommand='INSERT INTO "NETWORKS" ("NETID", "PICTUREPATH", "NETNAME") VALUES (:NETID, :PICTUREPATH, :NETNAME)'
        SelectCommand='SELECT * FROM "NETWORKS"'
        UpdateCommand='UPDATE "NETWORKS" SET "PICTUREPATH" = :PICTUREPATH, "NETNAME" = :NETNAME WHERE "NETID" = :original_NETID AND "PICTUREPATH" = :original_PICTUREPATH AND "NETNAME" = :original_NETNAME'>
        <DeleteParameters>
            <asp:Parameter Name="original_NETID" Type="String" />
            <asp:Parameter Name="original_NETNAME" Type="String" />
            <asp:Parameter Name="original_PICTUREPATH" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="original_NETID" Type="String" />
            <asp:Parameter Name="original_NETNAME" Type="String" />
            <asp:Parameter Name="original_PICTUREPATH" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="NETID" Type="String" />
            <asp:Parameter Name="NETNAME" Type="String" />
            <asp:Parameter Name="PICTUREPATH" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    &nbsp; &nbsp;
    <asp:SqlDataSource ID="NetTariff" runat="server" ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:WebPortal-New %>"
        OldValuesParameterFormatString="original_{0}"
        ProviderName="<%$ ConnectionStrings:WebPortal-New.ProviderName %>"
        SelectCommand='SELECT * FROM "TARIFFS" WHERE ("NETID" = :NETID)'
        DeleteCommand='DELETE FROM "TARIFFS" WHERE "TARID" = :original_TARID AND "NETID" = :original_NETID AND "MINUTES" = :original_MINUTES AND "TARNAME" = :original_TARNAME AND "DATARATEPERKB" = :original_DATARATEPERKB AND "MONTHLYRENT" = :original_MONTHLYRENT AND "TEXTMESSAGES" = :original_TEXTMESSAGES'
        InsertCommand='INSERT INTO "TARIFFS" ("MINUTES", "TARNAME", "DATARATEPERKB", "MONTHLYRENT", "TEXTMESSAGES", "TARID", "NETID") VALUES (:MINUTES, :TARNAME, :DATARATEPERKB, :MONTHLYRENT, :TEXTMESSAGES, :TARID, :NETID)'
        UpdateCommand='UPDATE "TARIFFS" SET "MINUTES" = :MINUTES, "TARNAME" = :TARNAME, "DATARATEPERKB" = :DATARATEPERKB, "MONTHLYRENT" = :MONTHLYRENT, "TEXTMESSAGES" = :TEXTMESSAGES WHERE "TARID" = :original_TARID AND "NETID" = :original_NETID AND "MINUTES" = :original_MINUTES AND "TARNAME" = :original_TARNAME AND "DATARATEPERKB" = :original_DATARATEPERKB AND "MONTHLYRENT" = :original_MONTHLYRENT AND "TEXTMESSAGES" = :original_TEXTMESSAGES'>
        <SelectParameters>
            <asp:ControlParameter ControlID="FormView1" DefaultValue="FormView1.SelectedValue"
                Name="NETID" PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:ControlParameter ControlID="FormView1" DefaultValue="FormView1.SelectedValue"
                Name="NETID" PropertyName="SelectedValue" Type="String" />
            <asp:Parameter Name="original_TARID" Type="String" />
            <asp:Parameter Name="original_NETID" Type="String" />
            <asp:Parameter Name="original_MINUTES" Type="Decimal" />
            <asp:Parameter Name="original_TARNAME" Type="String" />
            <asp:Parameter Name="original_DATARATEPERKB" Type="Decimal" />
            <asp:Parameter Name="original_MONTHLYRENT" Type="Decimal" />
            <asp:Parameter Name="original_TEXTMESSAGES" Type="Decimal" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:ControlParameter ControlID="FormView1" DefaultValue="FormView1.SelectedValue"
                Name="NETID" PropertyName="SelectedValue" Type="String" />
            <asp:Parameter Name="MINUTES" Type="Decimal" />
            <asp:Parameter Name="TARNAME" Type="String" />
            <asp:Parameter Name="DATARATEPERKB" Type="Decimal" />
            <asp:Parameter Name="MONTHLYRENT" Type="Decimal" />
            <asp:Parameter Name="TEXTMESSAGES" Type="Decimal" />
            <asp:Parameter Name="original_TARID" Type="String" />
            <asp:Parameter Name="original_NETID" Type="String" />
            <asp:Parameter Name="original_MINUTES" Type="Decimal" />
            <asp:Parameter Name="original_TARNAME" Type="String" />
            <asp:Parameter Name="original_DATARATEPERKB" Type="Decimal" />
            <asp:Parameter Name="original_MONTHLYRENT" Type="Decimal" />
            <asp:Parameter Name="original_TEXTMESSAGES" Type="Decimal" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="MINUTES" Type="Decimal" />
            <asp:Parameter Name="TARNAME" Type="String" />
            <asp:Parameter Name="DATARATEPERKB" Type="Decimal" />
            <asp:Parameter Name="MONTHLYRENT" Type="Decimal" />
            <asp:Parameter Name="TEXTMESSAGES" Type="Decimal" />
            <asp:Parameter Name="TARID" Type="String" />
            <asp:Parameter Name="NETID" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:FormView ID="FormView2" runat="server" CellPadding="4" DataKeyNames="TARID,NETID"
        DataSourceID="NetTariff" ForeColor="#333333" Style="z-index: 101; left: 553px;
        position: absolute; top: 140px" Width="312px" Height="258px" OnModeChanged="FormView2_ModeChanged">
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#7C6F57" />
        <EditItemTemplate>
            <asp:TextBox ID="MINUTESTextBox" runat="server" Text='<%# Bind("MINUTES") %>' style="z-index: 100; left: 131px; position: absolute; top: 156px">
            </asp:TextBox><br />
            <asp:TextBox ID="TARNAMETextBox" runat="server" Text='<%# Bind("TARNAME") %>' style="z-index: 101; left: 131px; position: absolute; top: 112px">
            </asp:TextBox><br />
            <asp:TextBox ID="DATARATEPERKBTextBox" runat="server" Text='<%# Bind("DATARATEPERKB") %>' style="z-index: 102; left: 131px; position: absolute; top: 201px">
            </asp:TextBox><br />
            <asp:TextBox ID="MONTHLYRENTTextBox" runat="server" Text='<%# Bind("MONTHLYRENT") %>' style="z-index: 103; left: 131px; position: absolute; top: 134px">
            </asp:TextBox><br />
            <asp:TextBox ID="TEXTMESSAGESTextBox" runat="server" Text='<%# Bind("TEXTMESSAGES") %>' style="z-index: 104; left: 131px; position: absolute; top: 178px">
            </asp:TextBox><br />
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 106; left: 15px; position: absolute; top: 46px" Text="Tariff Setup"></asp:Label>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 107; left: 16px; position: absolute; top: 45px" Text="Tariff Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 108; left: 15px; position: absolute;
                top: 92px" Text="ID"></asp:Label>
            <asp:Label ID="Label1" runat="server" Style="z-index: 109; left: 15px; position: absolute;
                top: 203px" Text="Data Rate:"></asp:Label>
            <asp:Label ID="Label2" runat="server" Style="z-index: 110; left: 15px; position: absolute;
                top: 158px" Text="Free Minutes:"></asp:Label>
            <asp:Label ID="Label3" runat="server" Style="z-index: 111; left: 15px; position: absolute;
                top: 180px" Text="Free Messages:"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 112; left: 15px; position: absolute;
                top: 114px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 117; left: 15px; position: absolute;
                top: 136px" Text="Monhly Rent:"></asp:Label>
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update" style="z-index: 115; left: 192px; position: absolute; top: 226px">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" style="z-index: 116; left: 244px; position: absolute; top: 226px">
            </asp:LinkButton>
        </EditItemTemplate>
        <RowStyle BackColor="#E3EAEB" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <InsertItemTemplate>
            <asp:TextBox ID="MINUTESTextBox" runat="server" Text='<%# Bind("MINUTES") %>' style="z-index: 100; left: 130px; position: absolute; top: 158px">
            </asp:TextBox><br />
            <asp:TextBox ID="TARNAMETextBox" runat="server" Text='<%# Bind("TARNAME") %>' style="z-index: 101; left: 130px; position: absolute; top: 114px">
            </asp:TextBox><br />
            <asp:TextBox ID="DATARATEPERKBTextBox" runat="server" Text='<%# Bind("DATARATEPERKB") %>' style="z-index: 102; left: 130px; position: absolute; top: 204px">
            </asp:TextBox>
            <asp:Label ID="NETIDLabel" runat="server" Style="z-index: 117; left: 36px; position: absolute;
                top: 79px">FormView1.SelectedValue</asp:Label>
            <br />
            <asp:TextBox ID="MONTHLYRENTTextBox" runat="server" Text='<%# Bind("MONTHLYRENT") %>' style="z-index: 104; left: 130px; position: absolute; top: 136px">
            </asp:TextBox><br />
            <asp:TextBox ID="TEXTMESSAGESTextBox" runat="server" Text='<%# Bind("TEXTMESSAGES") %>' style="z-index: 105; left: 130px; position: absolute; top: 181px">
            </asp:TextBox><br />
            <asp:TextBox ID="TARIDTextBox" runat="server" Text='<%# Bind("TARID") %>' style="z-index: 106; left: 130px; position: absolute; top: 92px">
            </asp:TextBox><br />
            <br />
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 107; left: 69px; position: absolute; top: 46px" Text="Tariff Setup"></asp:Label>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 108; left: 26px; position: absolute; top: 45px" Text="Tariff Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 109; left: 15px; position: absolute;
                top: 92px" Text="ID"></asp:Label>
            <asp:Label ID="Label1" runat="server" Style="z-index: 110; left: 15px; position: absolute;
                top: 203px" Text="Data Rate:"></asp:Label>
            <asp:Label ID="Label2" runat="server" Style="z-index: 111; left: 15px; position: absolute;
                top: 158px" Text="Free Minutes:"></asp:Label>
            <asp:Label ID="Label3" runat="server" Style="z-index: 112; left: 15px; position: absolute;
                top: 180px" Text="Free Messages:"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 113; left: 15px; position: absolute;
                top: 114px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 114; left: 15px; position: absolute;
                top: 136px" Text="Monhly Rent:"></asp:Label>
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" style="z-index: 115; left: 200px; position: absolute; top: 226px">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" style="z-index: 116; left: 244px; position: absolute; top: 226px">
            </asp:LinkButton>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="MINUTESLabel" runat="server" Text='<%# Bind("MINUTES") %>' style="z-index: 100; left: 115px; position: absolute; top: 173px"></asp:Label><br />
            <asp:Label ID="TARNAMELabel" runat="server" Text='<%# Bind("TARNAME") %>' style="z-index: 101; left: 115px; position: absolute; top: 115px"></asp:Label><br />
            <asp:Label ID="DATARATEPERKBLabel" runat="server" Text='<%# Bind("DATARATEPERKB") %>' style="z-index: 102; left: 115px; position: absolute; top: 152px">
            </asp:Label>
            <asp:Label ID="HeadingLbl" runat="server" Font-Size="XX-Large" ForeColor="LightSteelBlue"
                Style="z-index: 99; left: 26px; position: absolute; top: 47px" Text="Tariff Setup"></asp:Label>
            <br />
            <asp:Label ID="MONTHLYRENTLabel" runat="server" Text='<%# Bind("MONTHLYRENT") %>' style="z-index: 104; left: 115px; position: absolute; top: 135px">
            </asp:Label>
            <asp:Label ID="Heading1lbl" runat="server" Font-Size="XX-Large" ForeColor="Navy"
                Style="z-index: 105; left: 27px; position: absolute; top: 46px" Text="Tariff Setup"></asp:Label>
            <asp:Label ID="IDlbl" runat="server" Style="z-index: 106; left: 24px; position: absolute;
                top: 97px" Text="ID"></asp:Label>
            <asp:Label ID="Label1" runat="server" Style="z-index: 107; left: 24px; position: absolute;
                top: 152px" Text="Data Rate:"></asp:Label>
            <asp:Label ID="Label2" runat="server" Style="z-index: 108; left: 24px; position: absolute;
                top: 173px" Text="Free Minutes:"></asp:Label>
            <asp:Label ID="Label3" runat="server" Style="z-index: 109; left: 24px; position: absolute;
                top: 194px" Text="Free Messages:"></asp:Label>
            <asp:Label ID="NAMElbl" runat="server" Style="z-index: 110; left: 24px; position: absolute;
                top: 115px" Text="Name:"></asp:Label>
            <asp:Label ID="PIClbl" runat="server" Style="z-index: 111; left: 24px; position: absolute;
                top: 135px" Text="Monhly Rent:"></asp:Label>
            <br />
            <asp:Label ID="TEXTMESSAGESLabel" runat="server" Text='<%# Bind("TEXTMESSAGES") %>' style="z-index: 112; left: 115px; position: absolute; top: 194px">
            </asp:Label><br />
            <asp:Label ID="TARIDLabel" runat="server" Text='<%# Eval("TARID") %>' style="z-index: 113; left: 115px; position: absolute; top: 97px"></asp:Label><br />
            <asp:Label ID="NETIDLabel2" runat="server" Text='<%# Eval("NETID") %>' style="z-index: 114; left: 187px; position: absolute; top: 59px" Visible="False"></asp:Label><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit" style="z-index: 115; left: 207px; position: absolute; top: 229px">
            </asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Delete" style="z-index: 116; left: 251px; position: absolute; top: 229px">
            </asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New" style="z-index: 117; left: 174px; position: absolute; top: 229px" OnClick="NewButton_Click">
            </asp:LinkButton>
        </ItemTemplate>
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    </asp:FormView>
</asp:Content>

If u past the folowing code to user Visual WEB Developer u will get exactly what I am looking at with the exception that u dont have tables behind but it will give u n idea where i am standing.

This is the second solution I am working since the new record is not working in Gridview control mean I am unable to create new record in gridview control.

So if u know that how to create a row in grid view it will help me in creating master detail web forms and the question i first ask about formview thing will help in one-to-one relationship situation.

Please reply ASAP.  and I greatly appreciate your time and efforts. thanks again.
Zee
0
MateenAuthor Commented:
I am sorry in the long context I forget to ask what is happening

When I press new link in form view it opens up a insert mode but lose the value of NetID which is the relation ship b/w two tables and when i press insert link oracle give me an error that netid can't be null.
how I can get the value of netid in insert command value clause or initialize the value of net id textbox or label control in insert mode.

thanks again
0
ptleitchCommented:
I use something similar to this, but i am pulling the value from session.  I haven't taken a close look at your code yet and have no idea where your value is being stored.

protected void FormView1_ItemInserting(object sender, System.Web.UI.WebControls.FormViewInsertEventArgs e)
{
 SqlDataSource1.InsertParameters("NetID").DefaultValue = Session("UserNetID").ToString();
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MateenAuthor Commented:
I understand that but nomatter what I do when I get into the insert mode netid field is blank doesnt get the master key value. otherwise code is working fine
Thanks for your effort dear
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.