Update Panel Gridview not updating - c#

When i click the submit button data is updated in db,but it is not listing
in gridview
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="True"><ContentTemplate>
<fieldset style="border: thin dotted #000000; height:919px;width:70%;background-color:#999999;"><legend style="font-size:15px;color:rgb(255,255,255);">Registration</legend><div> <asp:TextBox ID="txtcode" runat="server" CssClass="textbox" placeholder="Code"></asp:TextBox> </div> <br /><div><asp:TextBox ID="txtabr" runat="server" CssClass="textbox" placeholder="AER"></asp:TextBox> </div><br /> <div><asp:TextBox ID="txtauthor" runat="server" CssClass="textbox" placeholder="Author"></asp:TextBox></div><br /><div><asp:TextBox ID="txtEmail" runat="server" CssClass="textbox" placeholder="Email"></asp:TextBox</div><br /><div>
<asp:TextBox ID="txtpublishdate" runat="server" CssClass="textbox" placeholder="PublishDate"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" BorderColor="#9900FF"
onclick="ImageButton1_Click" style="width: 14px"
/>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="Black" DayNameFormat="Shortest" Font-Names="Times New Roman"
Font-Size="10pt" ForeColor="Black" Height="220px" NextPrevFormat="FullMonth"
TitleFormat="Month" Width="400px" onselectionchanged="Calendar1_SelectionChanged"
>
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt"
ForeColor="#333333" Height="10pt" />
<DayStyle Width="14%" />
<NextPrevStyle Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#333333" Width="1%" />
<TitleStyle BackColor="Black" Font-Bold="True" Font-Size="13pt"
ForeColor="White" Height="14pt" />
<TodayDayStyle BackColor="#CCCC99" />
</asp:Calendar></div><br /> <div>
<asp:TextBox ID="txtname" runat="server" CssClass="textbox" placeholder="BookName"></asp:TextBox> </div><br /><div>
<asp:TextBox ID="txtduedate" runat="server" CssClass="textbox" placeholder="DueDate"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" BorderColor="#9900FF" onclick="ImageButton2_Click"
/>
<asp:Calendar ID="Calendar2" runat="server" BackColor="White"
BorderColor="Black" DayNameFormat="Shortest" Font-Names="Times New Roman"
Font-Size="10pt" ForeColor="Black" Height="220px" NextPrevFormat="FullMonth"
TitleFormat="Month" Width="400px" onselectionchanged="Calendar2_SelectionChanged"
>
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt"
ForeColor="#333333" Height="10pt" />
<DayStyle Width="14%" />
<NextPrevStyle Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#333333" Width="1%" />
<TitleStyle BackColor="Black" Font-Bold="True" Font-Size="13pt"
ForeColor="White" Height="14pt" />
<TodayDayStyle BackColor="#CCCC99" />
</asp:Calendar>
</div><div> <asp:Label ID="Label5" runat="server" Text="IsActive" CssClass="label"></asp:Label> </div> <div><asp:CheckBox ID="chkactive" runat="server" /></div><div>
<asp:Label ID="Label6" runat="server" Text="Status" CssClass="label"></asp:Label> </div> <div><asp:CheckBox ID="chkstactive" Text="Active" runat="server" Checked="true" /> <asp:CheckBox ID="chknotactive" Text="NotActive" runat="server" /></div><br /><div><asp:Button ID="Btnsubmit" runat="server" Text="Submit" CssClass="bluebutton" onclick="Btnsubmit_Click" /> </div></fieldset></ContentTemplate></asp:UpdatePanel>
</div>
<div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="True"><ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="#CC33FF" BorderColor="Black" ForeColor="White">
<AlternatingRowStyle BackColor="#666633" />
<Columns>
<asp:BoundField DataField="Code" HeaderText="Code" />
<asp:BoundField DataField="Author" HeaderText="Author" />
<asp:BoundField DataField="AER" HeaderText="ABR" />
</Columns>
<HeaderStyle BackColor="Black" />
<RowStyle BackColor="#666699" />
<SelectedRowStyle BackColor="#00FF99" />
</asp:GridView> </ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="Btnsubmit" EventName="Click" /></Triggers> </asp:UpdatePanel> </div> </form></body>
Data Successfully updated in table,after the insert gridview is not listing the latest record,if i refresh the page again the data will shown.please help ...........
protected void Btnsubmit_Click(object sender, EventArgs e)
{OleDbConnection conn = new OleDbConnection(); conn.ConnectionString =ConfigurationManager.ConnectionStrings["conn"].ToString();conn.Open();
string query = "insert into Register
(Code,Author,AER,PublishDate) values('" + txtcode.Text + "','" +
txtauthor.Text + "','" + txtabr.Text + "','" + txtpublishdate.Text + "')";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
BindGrid();
Clear();
}
protected void BindGrid()
{

Add code to your BindGrid() method to re-bind datagridview to a new data.
Something like this:
// Set up the data source.
bindingSource.DataSource = GetData("Select * From Register");
GridView1.DataSource = bindingSource;

In your BindGrid data add following code
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Register", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
Gridview1.DataSource = ds;
Gridview1.DataBind();
UpdatePanel1.Update();
}

Related

how to get values from gridview in asp.net web forms?

hello all i am new to asp.net and i want to get values from grid view when i click on Edit or Delete or and i don't know how to do it i am sending data table to show table data and i don't want to use SQL Data Source from Visual tool box.
i have tried the following code but it gives error
protected void dgv1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int rowindex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
dgv1.EditIndex = rowindex;
dgv1.DataBind();
}
}
}
my view page code is as follows
<form id="form1" class="form-control form-group" runat="server">
<asp:Panel ID="pnlAddCustomers" runat="server" Height="376px">
<asp:Label ID="lblAddCustomers" runat="server" Text="Add Customers"></asp:Label>
<br runat="server"/>
<asp:Label ID="labelAddName" Text="Customer Name" runat="server"></asp:Label>
<asp:TextBox ID="txtboxcustomername" runat="server" Height="16px"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text=" Customer City "></asp:Label>
<asp:TextBox ID="txtboxcity" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text=" Customer Telephone "></asp:Label>
<asp:TextBox ID="txtboxtelephone" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Add Customers" Height="57px" Width="208px" OnClick="Button1_Click" />
</asp:Panel>
<asp:Panel ID="PnlViewCustomers" CssClass="table-dark" runat="server" Height="408px" >
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
<asp:GridView ID="dgv1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" EnableTheming="True" PageSize="5" Width="100%" OnRowCommand="dgv1_RowCommand">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</asp:Panel>
</form>
and body pic is as follow
enter image description here
Try this:
LinkButton lnkBtn = (LinkButton)e.CommandSource; // the button
GridViewRow gvRow = (GridViewRow)lnkBtn.Parent.Parent; // the row
You may also get the data key index by adding DataKeyNames="MyTableKeyID" to the <asp:GridView /> tab, then
string selectedKeyIndex = this.GridView1.DataKeys[myRow.RowIndex]["MyTableKeyID"].ToString();

how to set the asp.net calendar to show only the specific date range

I am working on an etime application that has a drop-down list for paygroup and based on the pay group selected the employee drop down-list with in that paygroup is populated i then take the dates they have transactions for and do a min and max on those dates and fill the AvailableDateRange MIN-MAX. The question i have is i would like the calendar to only display the min and max date range for the from date and to date any thing greater than the max and anything less than the min should be greyed out. Any Help will be appreciated
The default.aspx code
<asp:Label ID="Label1" runat="server" Text="PayGroup"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" Height="25px"
Width="190px" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Paygroup" DataValueField="Paygroup"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EtimeHistoryConnectionString %>"
SelectCommand="SELECT Paygroup FROM dbo.EtimeEmployees GROUP BY Paygroup">
</asp:SqlDataSource>
<asp:Label ID="Label2" runat="server" Text="Employee"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" Height="25px" Width="428px"
AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="employee"
DataValueField="empid"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:EtimeHistoryConnectionString %>"
SelectCommand="SELECT Paygroup, EtimeEmpID AS empid, EmpName + ' - ' + EtimeEmpID AS employee FROM EtimeEmployees WHERE (Paygroup = #paygroup) ORDER BY EmpName">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="paygroup"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:EtimeHistoryConnectionString %>"
SelectCommand="SELECT MIN(TransDate) AS mindate, MAX(TransDate) AS maxdate FROM dbo.EtimePunchDetail WHERE (EmpID = #empid)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="empid"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:Label ID="Label3" runat="server" Text="AvailableDateRange MIN-MAX"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="mindate"
DataValueField="mindate" AutoPostBack="True"
onselectedindexchanged="DropDownList3_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="Label6" runat="server" Text="->"></asp:Label>
<asp:DropDownList ID="DropDownList4" runat="server"
DataSourceID="SqlDataSource3" DataTextField="maxdate"
DataValueField="maxdate" AutoPostBack="True"
onselectedindexchanged="DropDownList4_SelectedIndexChanged">
</asp:DropDownList>
</p>
<p>
<asp:Label ID="Label4" runat="server" Text="From Date" ForeColor="Red"></asp:Label>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ondayrender="Calendar1_DayRender"
ShowGridLines="True" Width="945px" SelectionMode="None">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</asp:Calendar>
<asp:Label ID="Label5" runat="server" Text="To Date" ForeColor="Red"></asp:Label>
<asp:Calendar ID="Calendar2" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="945px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</asp:Calendar>
I Tried This
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date == DateTime.Parse(DropDownList3.Text))
{
e.Day.IsSelectable = true;
}
if (e.Day.Date < DateTime.Parse(DropDownList3.Text))
{
e.Day.IsSelectable = false;
}
}
You can do it by handling the DayRender event:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date > DateTime.Now) // use any selection criteria
{
// you can do all kinds of stuff here
e.Cell.Enabled = false;
e.Cell.ForeColor = Color.DarkGray;
}
}

why on clicking on edit button of childgridview the childgridview hides?

This is what I have done for nested gridview :
The jQuery I have used to maintain this show hide is as:
<script type="text/javascript">
// Method for managing opening of gridview on + image and - image
$("[src*=plus]").live("click", function() {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "../Image/minus.gif");
});
$("[src*=minus]").live("click", function() {
$(this).attr("src", "../Image/plus.gif");
$(this).closest("tr").next().remove();
});
</script>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" DataKeyNames="num"
AutoGenerateColumns="False" Style="font-size: x-small" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
OnRowCancelingEdit="GridView1_RowCancelling" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand"
OnRowDeleting="GridView1_RowDeleting" ShowFooter="True"
OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting"
AllowSorting="true">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="../Image/plus.gif" />
<asp:Panel ID="pnlOrders" style="display:none;">
<asp:GridView ID="GridView3" runat="server" CellPadding="4" ForeColor="#333333" DataKeyNames="sno"
OnRowCancelingEdit="GridView3_RowCancelling" OnRowUpdating="GridView3_RowUpdating"
OnRowEditing="GridView3_RowEditing" AutoGenerateColumns="False" Style="font-size: x-small">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<HeaderTemplate>
Detailed Head
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="empdetails" Width="200px" runat="server" Text='<%# Eval("Details") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtempdetail" Width="200px" runat="server" MaxLength="9" Text='<%# Eval("Details") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sal" HeaderText="salary" />
<asp:CommandField ShowEditButton="true" EditText="Edit" />
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="View" runat="server" Text="View" CommandName="view"
CommandArgument='<%#Container.DataItemIndex+1 %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Age</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblage" Width="80px" runat="server" MaxLength="4" Text='<%# Eval("age") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtage" runat="server" Text='<%# Eval("age") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
BloodGroup</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblBloodGroup" Width="100px" runat="server" MaxLength="9" Text='<%# Eval(" BloodGroup") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBloodGroup" runat="server" Text='<%# Eval(" BloodGroup") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="Select" />
<asp:CommandField DeleteText="Reject" ShowDeleteButton="True" />
<asp:CommandField ShowEditButton="true" EditText="Edit" />
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
On server side this is what I am doing:
protected void GridView3_RowEditing(object sender, GridViewEditEventArgs e)
{
DataSet ds = new DataSet();
tBL objBL = new tBL();
GridViewRow editedRow = GridView1.Rows[e.NewEditIndex];
//now search row for your control...
GridView GridView3 = (GridView)editedRow.FindControl("GridView3");
GridView3.EditIndex = e.NewEditIndex;
objtxtToTableBL.ViewBL(dt);
GridView3.DataSource = dt;
GridView3.DataBind();
}
protected void GridView3_RowCancelling(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
}
protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
}
I am binding the nested gridview on rowdatabound of GridView1 and that works fine.
The problem with all this is when I click on the edit button of innergridview(child) it get hide as the page postback .
What should I do so that when I click on its edit button the child gridview remains open and it gets hides only when I click on minus button. Please help it has already taken 3 days of mine.

Import csv file into existing gridview

I have a tabcontainer with two tabs:
The first tab contains a button.
The second tab contains a gridview that has three textboxes.
I would like to do the following: when one clicks on the button in tab1, the gridview in tab2 is populated with data in a prespecified csv file (note that the file has the same column names as the gridview).
This is what I have so far, but for some reason, the gridview doesn't get populated with the data in the csv.
aspx.cs
<asp:UpdatePanel ID="WholeUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" HeaderText=""
Width="900px" TabStripPlacement="Top" ScrollBars="None" UseVerticalStripPlacement="false"
VerticalStripWidth="120px" BackColor="White" BorderColor="White"
Style="margin-right: 84px">
<asp:TabPanel ID="OptionPanel" runat="server" Height="600px">
<HeaderTemplate>
Simulation Option
</HeaderTemplate>
<ContentTemplate>
<asp:Button ID="PreviousSimButton" runat="server" Text="Run Previous Simulation" Width="250px" OnClick="PreviousSimButton_OnClick" />
<ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel1" runat="server" Height="600px" >
<HeaderTemplate>
General
</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="TestUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="GeneralPanel" runat="server" Height="274px">
<div style="overflow: auto; height: 222px; width: 100%">
<asp:GridView ID="InflationGridView" runat="server" AutoGenerateColumns="False" Width="52%"
ShowHeaderWhenEmpty="True" CellPadding="4" ForeColor="#333333" GridLines="None"
AllowSorting="True" ShowFooter="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" Height="2px" />
<Columns>
<asp:TemplateField HeaderText="Start Year">
<ItemStyle Font-Size="13px" Width="20%" HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="StartInflationTextBox" runat="server" Width="60px" Text="" Style="text-align: center;"></asp:TextBox>
<asp:NumericUpDownExtender ID="StartInflationNumericUpDownExtender" runat="server"
TargetControlID="StartInflationTextBox" Minimum="1" Width="60">
</asp:NumericUpDownExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Year">
<ItemStyle Font-Size="13px" Width="20%" HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="EndInflationTextBox" runat="server" Width="60px" Text="" Style="text-align: center;"></asp:TextBox>
<asp:NumericUpDownExtender ID="EndInflationNumericUpDownExtender" runat="server"
TargetControlID="EndInflationTextBox" Minimum="1" Width="60">
</asp:NumericUpDownExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Inflation Rate">
<ItemStyle Font-Size="13px" Width="25%" HorizontalAlign="Center" Height="2px" />
<ItemTemplate>
<asp:TextBox ID="InflationTextBox" runat="server" Text="" Width="60px" Style="text-align: center;"></asp:TextBox>
%
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="AddNewInflationRowButton" runat="server" Text="Add New Row" OnClick="AddNewInflationRowButton_Click"
Height="25px" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle Font-Bold="True" ForeColor="White" Height="20px" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" Height="10px" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</contenttemplate>
</asp:TabPanel>
</asp:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
aspx.cs
protected void PreviousSimButton_OnClick(object sender, EventArgs e)
{
TabContainer1.ActiveTabIndex = 1;
string file = "C:\\inst_research\\MonteCarlo\\Data\\inflation.csv";
InflationGridView.DataSource = (DataTable)ReadToEnd(file);
InflationGridView.DataBind();
WholeUpdatePanel.Update();
TestUpdatePanel.Update();
}
private object ReadToEnd(string filePath)
{
DataTable dtDataSource = new DataTable();
string[] fileContent = File.ReadAllLines(filePath);
if (fileContent.Count() > 0)
{
string[] columns = fileContent[0].Split(',');
for (int i = 0; i < columns.Count(); i++)
{
dtDataSource.Columns.Add(columns[i]);
}
for (int i = 1; i < fileContent.Count(); i++)
{
string[] rowData = fileContent[i].Split(',');
dtDataSource.Rows.Add(rowData);
}
}
return dtDataSource;
}
Your code should not give any issues if you use :
fileContent.Length instead of fileContent.Count()

How to call postback from TextBox on TextChange event without focus being changed?

The sitiation:
I need to databind the gridview inside the Ajax UpdatePanel each time user types letter inside my TextBox control. How to override the TextChange event to force it do postback for me?
Thanks!
<script type="text/javascript">
function ace1_itemSelected(sender, e) {
var hdCustID = $get('<%= hdCustID.ClientID %>');
hdCustID.value = e.get_value();
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblCustName" Text="Cust Name:" AssociatedControlID="txtCustName" runat="server" />
<asp:TextBox ID="txtCustName" AutoPostBack="false" AutoComplete="Off" runat="server" OnTextChanged="txtCustName_TextChanged" />
<ajaxToolkit:AutoCompleteExtender id="ace1" targetcontrolid="txtCustName" ServicePath="~/WebServices/FoodItemSuggestionService.asmx" servicemethod="FindTitles"
minimumprefixlength="1" OnClientItemSelected="ace1_itemSelected" firstrowselected="false" runat="server" />
<asp:HiddenField ID="hdCustID" runat="server" />
<br />
<br />
<br />
<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="4" BorderStyle="Groove">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<asp:BoundField DataField="Title" HeaderText="Название" SortExpression="Title" />
<asp:BoundField DataField="CategoryTitle" HeaderText="Категория" SortExpression="CategoryTitle" />
</Columns>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
protected void txtCustName_TextChanged(object sender, EventArgs e)
{
try
{
gvCustomer.DataSource = FoodItemBO.FindFoodItems(hdCustID.Value);
gvCustomer.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
Try this one:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
JQUERY:
$("#txtName").keydown(function(){
$("#form1").submit();
});

Categories

Resources