I HAVE PROBLEM IN AJAX calender control WITH gridview

Posted by Nuwan under ASP.NET on 4/23/2012 | Points: 10 | Views : 2076 | Status : [Member] | Replies : 5
Dear All,

I bind gridview using sql data table. I add textbox inside a gridview and give a ajax calender control for that textbox,
It work fine. Now I want to get a that textbox value as a variable. Please help me that matter.

<asp:TemplateField HeaderText="Bank Date">
<ItemTemplate>
<asp:TextBox ID="TextDate" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextDate" PopupButtonID="TextDate" CssClass="cal_Theme1">
</cc1:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="OK" />
</Columns>

This is my binding calender control textbox in gridview.

Rathnayake


Responses

Posted by: GSM_GSV on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
c#
string DateVal = ((TextBox)Gridview1.FooterRow.FindControl("TextDate")).Text;


vb
Dim DateVal As String = CType(Gridview1.FooterRow.FindControl("TextDate"),TextBox).Text


Here, In my example Text box is in footer template of grid view. Search appropriately for item template

Ref:http://geekswithblogs.net/casualjim/articles/51360.aspx

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Dear,

I got a error...
System.NullReferenceException: Object reference not set to an instance of an object.


Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GSM_GSV on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Can you please attach the screenshot of error and complete code(design and code behind) of gridview

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3"
Width="950px">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="B_SLIPNO"
DataTextField="B_SLIPNO" HeaderText="Print" DataNavigateUrlFormatString="PRINT_CASH_CREDIT_SLIP.aspx?dt={0}" NavigateUrl="~/PRINT_CASH_CREDIT_SLIP.aspx" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>

<asp:BoundField DataField="B_BRANCH" HeaderText="Slip No" SortExpression="B_BRANCH">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="B_SLIPNO" HeaderText="No" SortExpression="B_SLIPNO">
<HeaderStyle Width="35px" CssClass="hideHeader" />
<ItemStyle CssClass="hideGridColumn" />
</asp:BoundField>
<asp:BoundField DataField="B_DATE" HeaderText="Date" SortExpression="B_DATE" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OBK_NAME" HeaderText="Bank" SortExpression="OBK_NAME" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="B_AMOUNT" HeaderText="Amount" SortExpression="B_AMOUNT" DataFormatString="{0:N}">
<HeaderStyle Width="90px" />
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:TemplateField HeaderText="Bank Date">
<ItemTemplate>
<asp:TextBox ID="TextDate" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextDate" PopupButtonID="TextDate" CssClass="cal_Theme1">
</cc1:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="OK" />

</Columns>
<HeaderStyle BackColor="Brown" CssClass="GridViewHeaderStyle" />
<AlternatingRowStyle BackColor="RosyBrown" />
</asp:GridView>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:FINANCEConnectionString %>"
SelectCommand="SELECT BANK_SUM.B_SLIPNO, BANK_SUM.B_BRANCH, BANK_SUM.B_AMOUNT, BANK_SUM.B_BANK,BANK_SUM.B_DATE, BANKACC.OBK_NAME FROM BANK_SUM INNER JOIN BANKACC ON BANK_SUM.B_BANK = BANKACC.OBK_CODE WHERE (BANK_SUM.B_BRANCH = @BC) AND (BANK_SUM.B_DATE between '4/19/2012' and @BD)AND (B_STA='N') ORDER BY BANK_SUM.B_SLIPNO">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox4" Name="BC" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox3" Name="BD" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>

This is my gridview............
Actually i want to update my one of table.....

this is my coading

Dim DateVal As String = CType(Gridview1.FooterRow.FindControl("TextDate"),TextBox).Text


Using cons As SqlConnection = New SqlConnection(GetConnectionString)
Using cmds As SqlCommand = New SqlCommand
cmds.Connection = cons
cmds.CommandType = CommandType.Text


cmds.CommandText = "UPDATE CASHBOOK SET CA_BANK_DAT = '" + CDate(DateVal ) + "' WHERE(CA_REF = '" & mCNO & "')"


cons.Open()
cmds.ExecuteNonQuery()
cons.Close()
' Response.Redirect(Request.Url.AbsoluteUri)
End Using
End Using


I attached screen shots.

Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GSM_GSV on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Enable footer in gridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" ShowFooter="True" 

Width="950px">


Try this, if you dont get, plz wait I will check and see

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response