0 Replies - 3617 Views - Last Post: 02 November 2011 - 01:37 AM Rate Topic: -----

#1 rizwanit  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 11-October 11

Search ItemTemplate textbox value present in gridview with buttonclick

Posted 02 November 2011 - 01:37 AM



My Scenario is that i had a gridview,i had taken itemtemplate textboxes and a button,when the gridview is loaded the user enters a ServiceCode based on the ServiceCode and on button click,data should be displayed into the gridview,when the data is displaye in the gridview the user enters the quantity and the discount then the result should be displayed in the netamount,i had written the code but it is not working i would appreciate if someone share thier knowledge with me,my code is

DataSet dss = new DataSet();
SqlConnection MyConnection = new SqlConnection("server=prog;database=mydatabase;UID=sa;PWD=nato123;");

SqlCommand sqlcmd = new SqlCommand("select * from [Bill]", MyConnection);

SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
adp.Fill(ds);

GridView1.DataSource = ds.Tables[0];

GridView1.DataBind();
}

My Axpx Code is:

<asp:GridView ID="GridView1" runat="server" Height="157px" Width="639px"
AutoGenerateColumns="False" BorderWidth="1px"
HorizontalAlign="Justify" onrowdatabound="GridView1_RowDataBound"
BackColor="LightGoldenrodYellow" BorderColor="Tan" CellPadding="2"
ForeColor="Black" GridLines="None" onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="#FFFFC4" Font-Bold="True" ForeColor="#BF6000"/>
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="label10" runat="server" Font-Bold="true" ForeColor="#BF6000" Text="<%# Container.DataItemIndex + 1 %>">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Code" >
<ItemTemplate>
<asp:TextBox ID="TxtServiceCode" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceCode") %>'
runat="server" Width="55px">
</asp:TextBox>

<asp:Button ID="Insert" runat="server" BackColor="Ivory" CommandName="InsertRecord"
Font-Bold="True" ForeColor="#BF6000" Text="Insert" onclick="Insert_Click"/>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="TxtName" runat="server" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Width="150px" Text='<%# DataBinder.Eval(Container, "DataItem.ServiceName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Amt">
<ItemTemplate>
<asp:TextBox ID="TxtServiceAmount" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceAmount") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="TxtQuantity" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Quantity") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disc Amt">
<ItemTemplate>
<asp:TextBox ID="TxtdiscAmt" Font-Bold="true" ForeColor="#BF6000" Text ='<%# DataBinder.Eval(Container,"DataItem.Discount") %>'
AutoPostBack="true" OnTextChanged="TxtdiscAmt_TextChanged" runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Net Amt">
<ItemTemplate>
<asp:TextBox ID="lblNet" runat="Server" Font-Bold="true" ForeColor="#BF6000" Width="55" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>


MY CS Code is:
DataSet dss = new DataSet();
SqlConnection MyConnection = new SqlConnection("server=prog;database=mydatabase;UID=sa;PWD=nato123;");

SqlCommand sqlcmd = new SqlCommand("select * from [Bill]", MyConnection);

SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
adp.Fill(ds);

GridView1.DataSource = ds.Tables[0];

GridView1.DataBind();
}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1