SP Gridview link button column not working - c#

I have one sharepoint custom page application which is rendering from a user control. In the user control page, i had used SPGridview for displaying data. My first column is Title Column (link button column), when the user click on the link, then one popup window will open with corresponding data. But the problem is the link button is not working properly. But this application is working as fine in asp.net application.
My code is shown below..
<asp:UpdatePanel runat="server" ID="UpdatePanel2">
<ContentTemplate>
<SharePoint:SPGridView ID="dgApplicationBox" CellPadding="0" Height="100%" runat="server"
ForeColor="Black" Font-Size="10px" Font-Names="Verdana" AutoGenerateColumns="False"
AllowPaging="True" Width="100%" BorderStyle="None" BorderWidth="0px" PageSize="10"
BorderColor="White" BackColor="White" OnRowDataBound="dgApplicationBox_RowDataBound"
DataKeyNames="ApplicationID" OnSelectedIndexChanged="dgApplicationBox_SelectedIndexChanged"
OnPageIndexChanging="dgApplicationBox_PageIndexChanging" CssClass="ms-listviewtable"
AlternatingRowStyle-CssClass="ms-alternating">
<SelectedRowStyle Font-Bold="True" ForeColor="Black" BackColor="#CE5D5A"></SelectedRowStyle>
<EditRowStyle Font-Size="10px" Font-Names="Verdana,Arial,Helvetica,sans-serif"></EditRowStyle>
<HeaderStyle Font-Size="11px" Height="20px" Font-Bold="True" ForeColor="Black" BackColor="#E7E8EC">
</HeaderStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#414E61" Font-Size="5px" Font-Names="arial"
Height="10px" BackColor="#EBF3FF"></PagerStyle>
<RowStyle />
<Columns>
<asp:TemplateField HeaderText="Title" HeaderStyle-CssClass="ms-vb">
<ItemTemplate>
<asp:LinkButton ID="lbtnSubject"
Text='<%# Bind("UDF5") %>' runat="server" OnClick="lbtnSubject_Click"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Request No.">
<ItemTemplate>
<asp:Label ID="lblReqNo" Text='<%# Bind("UDF1") %>' runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
<asp:BoundField DataField="CreatedOn" HeaderText="Created On" DataFormatString="{0:MM/dd/yyyy}"
HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle CssClass="ms-vb2"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Form Type" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle CssClass="ms-vb2"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="History">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="21px" CssClass="ms-vb2">
</ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="lbtnView" runat="server" OnClick="lbtnView_Click" >View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Application Id" Visible="False">
<ItemTemplate>
<asp:Label ID="lblApplicationId" runat="server" Text='<%# Bind("ApplicationId") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
</ContentTemplate>
</asp:UpdatePanel>
when the user click on the link button, this code will works..
try
{
clearSession();
Session["DigitalSignature"] = null;
Button btnDetails = sender as Button;
DataTable dt = (DataTable)dgApplicationBox.DataSource;
GridViewRow gvRow = (GridViewRow)(sender as LinkButton).Parent.Parent;
Session["AppId"] = ((Label)gvRow.FindControl("lblApplicationId")).Text;
string subject = ((LinkButton)gvRow.FindControl("lbtnSubject")).Text;
WFInfo objWFInfo = new WFInfo();
objWFInfo.InitWorkflowProperty(Convert.ToInt32(Session["AppId"].ToString()), Session["CurrentUser"].ToString());
Session["FormId"] = objWFInfo.FormID.ToString();
string strFilname = objWFInfo.GetFormName(objWFInfo.ApplicationCategoryID.ToString());
string WindowName = strFilname;
strFilname += ".aspx";
Session["CategoryId"] = objWFInfo.ApplicationCategoryID.ToString();
//pnlSubmitModal_ModalPopupExtender.Show();
ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "popUpWindow('" + strFilname + "?tittle=" + subject + "', 800, 690,'" + WindowName + "');", true);
this.Controls.Add(new LiteralControl("<script>alert('hi');</script>"));
if (Session["CurrentUser"] != null)
{
ApplicationForm objApplication = new ApplicationForm();
objApplication.markRead(Convert.ToInt32(Session["AppId"].ToString()), Session["CurrentUser"].ToString());
}
bindFolderData();
}
If i click on the link button, there will be only post back occuring. but not the popup window open.. Please help me for resolving this problem. thanks in advance..

Have you checked to see if you're receiving a javascript error on the click?
Have you tried setting UpdatePanel2's UpdateMode="Conditional" and then adding Triggers? (button click)
Like this sample:
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbtnSubject" EventName="Click" />
</Triggers>

Related

How to get the row index of a dynamically created asp.net GridView?

How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
This is the GridView:
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="RefID">
<ItemTemplate>
<asp:Label ID="lbl_Refid" runat="server" Text='<%# Eval("Refid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbl_date" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name Of Company">
<ItemTemplate>
<asp:Label ID="lbl_noc" runat="server" Text='<%# Eval("Name_Of_Company") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact/Email">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Contact") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Remarks") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btn_edit" runat="server" `enter code here` Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand = "OnRowCommand">
Use
OnRowCommand = "OnRowCommand"
Now when any action happen on the grid the OnRowCommand event is executed.
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
}
More Info
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="MyButtonClick" />
</ItemTemplate>
and your method
protected void MyButtonClick(object sender, System.EventArgs e)
{
//Get the button that raised the event
Button btn = (Button)sender;
//Get the row that contains this button
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
}

Update GridViewRow on button click of that row

I have a GridView with checkbox, dropdown and button as templatefields.
On button click I have to update the entire row in the data base.
This is my aspx:
<asp:GridView runat="server" ID="Gdv" AutoGenerateColumns="False" Font-Size="Small" CssClass="grid" BackColor="White" BorderWidth="0px" CellPadding="4" Width="100%" AllowSorting="True" SkinID="GVSalesManager" GridLines="none" AllowPaging="true" PageSize="10" PagerStyle-ForeColor="#0066cc" PagerStyle-CssClass="gvPagerCss" PagerStyle-Font-Underline="true" PagerStyle-Wrap="true"
OnPageIndexChanging="GdvCPRetailerMap_PageIndexChanging" OnRowDataBound="GdvCPRetailerMap_RowDataBound">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="S.No" DataField="S.No." SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="2%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="2%"/>
</asp:BoundField>
<asp:TemplateField ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" OnCheckedChanged="chkRow_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" HeaderText="Customer Id" ItemStyle-HorizontalAlign="Center" DataField="CustomerID" SortExpression="CustomerID">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Firm's Name" ItemStyle-HorizontalAlign="Center" DataField="Firm's Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Retailer Name" ItemStyle-HorizontalAlign="Center" DataField="Retialer Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Pesticide Licence No." ItemStyle-HorizontalAlign="Center" DataField="Pesticide Licence No" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:TemplateField HeaderText="Channel Partner-1" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP1" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP1_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Channel Partner-2" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP2" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP2_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button runat="server" ID="BtnUpdateRow" Text="Update" ToolTip="Update This Record?" OnClick="BtnUpdateRow_Click" BackColor="#336699" ForeColor="#ffffff"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This is the updatebutton event
protected void BtnUpdateRow_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow grow = (GridViewRow)btn.NamingContainer;
//btn.
CheckBox chkbx = (CheckBox)grow.FindControl("chkRow");
if (chkbx.Checked != true)
{
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Red;
labelErrormessage.Text = "Please Check/Uncheck the CheckBox and Click Update";
return;
}
else
{
/*--Code to update the row's record in the edatabase.--*/
??
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}
}
How do I read the row in which the button has been clicked and update its dropdownlist selected values in the database?
If you have some sort of identification data displayed in the gridview you could get the value from the row's cell like this grow.Cells[0].Text then find the record in the database and update its values.
You could also hide the id for example if this is information you dont want to show to the user. The row will still be located at index 0 but hidden.
Sample:
else
{
var record = queryDatabase(grow.Cells[0].Text);
//update record values
updateRecord(record);
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}

GridView affected by window.open

I have a gridView which works nicely until I open a new window by clicking a button. When the new window is opened the values in one of the columns 'lblTotalPrice' gets erased. 'lblTotalPrice' is a template field, which is calculated in MealList_RowDataBound (quantity * price). The footer for the column, however is not affected when the new window is opened (also gets its value in MealList_RowDataBound).
Also the font-size of the data-bound columns are changed when the new window is opened.
Any ideas of what might cause this? When stepping through the code there are no other lines executed after btnEnvComment_Click
When gridView is databound again, everything is back to normal.
The gridView:
<rwg:BulkEditGridView ID="MealList" runat="server" AutoGenerateColumns="False" ShowFooter="True" GridLines="Vertical" CellPadding="4"
BackColor="White" DataKeyNames="ItemId,ProductId" SaveButtonID="SaveButton"
DataSourceID="SqlMealItems" style="float:left"
OnRowDataBound="MealList_RowDataBound" OnRowCreated="MealList_RowCreated" CssClass="gridView">
<AlternatingRowStyle CssClass="MealListItemAlt" BackColor="#a6dbed" />
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="Prod #" HeaderStyle-Wrap="false" ReadOnly="True" >
<HeaderStyle Wrap="False" Width="60px"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="ProductName" HeaderText="Namn" ReadOnly="True" ItemStyle-Wrap="False" >
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Quantity" HeaderText="Antal" ControlStyle-CssClass="numeric" >
<ControlStyle CssClass="numeric" Width="30px"></ControlStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Enhet">
<ItemTemplate>
<asp:DropDownList ID="DropDownUnit" OnSelectedIndexChanged="DropDownUnit_SelectedIndexChanged"
AutoPostBack="False" runat="server" DataTextField="Unit" DataValueField="Unit">
</asp:DropDownList>
</ItemTemplate>
<ControlStyle Width="70px" />
</asp:TemplateField>
<asp:BoundField HeaderText="รก pris" ReadOnly="True" ControlStyle-CssClass="rightAlign" ItemStyle-Wrap="False">
<ControlStyle CssClass="numeric" ></ControlStyle>
<ItemStyle HorizontalAlign="Right" Width="80px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Totalt" ItemStyle-Wrap="False">
<ItemTemplate>
<asp:label ID="lblTotalPrice" runat = server></asp:label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" Width="80px" />
<FooterTemplate>
<asp:Label ID="lblTotalPricePerMeal" runat="server"></asp:Label>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" Font-Bold="true" Font-Overline="True" Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="Unit" HeaderText="h" ReadOnly="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:image runat="server" ID="imgBlob" Width="24"></asp:image>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" ID="lblError"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="MealListFooter" />
<HeaderStyle CssClass="MealListHead" />
</rwg:BulkEditGridView>
The code for the button that open the new window:
protected void btnEnvComment_Click(object sender, EventArgs e)
{
int offsetPos = 125; // set placement of new window
String URL = "EnvComment.aspx?MealID=" + Session["MealId"];
String responsCommand = "window.open('" + URL + "','_blank','height=400,width=300,top=" + ",left=" + offsetPos.ToString() + offsetPos.ToString() + ",titlebar=1')";
Response.Write("<script>");
Response.Write(responsCommand);
Response.Write("</script>");
}

storing Multiple selected radiobutton's of gridview?

I have gridview which contains 60 rows and each row has 4 radiobutton option (select any one). To opearate that code , on submit button wrote code as follows . I didn't work.
My design view :
<asp:GridView ID="gvSurvey" runat="server" CellPadding = "4" OnRowDataBound ="gvSurvey_RowDataBound" BorderWidth ="2"
AutoGenerateColumns="False" EmptyDataText="No data Available" GridLines="None"
HorizontalAlign="Center" ForeColor="#333333" Font-Names="Verdana" ShowFooter="True">
<RowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="HEADER" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="QTN_NO" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="SQTN_NO" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField Visible="true" HeaderText ="Strongly Disagree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn1" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton1" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Agree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn2" runat ="server" GroupName ="MyRadioGroup"/>
<%--<asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton2" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Disagree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn3" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton3" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Strongly Agree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn4" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%-- <input name="MyRadioButton4" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
</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>
C#
for (i = 0; i < gvSurvey.Rows.Count; i++)
{
RadioButton rdbtn1 = (RadioButton)gvSurvey.Rows[i].Cells[3].FindControl("rdbtn1");
RadioButton rdbtn2 = (RadioButton)gvSurvey.Rows[i].Cells[4].FindControl("rdbtn2");
RadioButton rdbtn3 = (RadioButton)gvSurvey.Rows[i].Cells[5].FindControl("rdbtn3");
RadioButton rdbtn4 = (RadioButton)gvSurvey.Rows[i].Cells[6].FindControl("rdbtn4");
// RadioButton rdbtn1=(RadioButton) gvSurvey.Rows[i].ClientID
qtn_no = dtSurvey.Rows[i]["QTN_NO"].ToString();
sqtn_no = dtSurvey.Rows[i]["SQTN_NO"].ToString();
if (rdbtn1.Checked)
{
rdbtn1.Text = "1";
lblMsg.Text = nominationsBiz.SaveSuggestion(ticketNo.ToString(), qtn_no, sqtn_no, rdbtn1.Text);
}
Please Go through the following code you will find the Solutions
// It will be on your submit button click
protected void getPinCode()
{
foreach (GridViewRow grdRows in gvSurvey.Rows)
{
RadioButton rbt1 = (RadioButton)grdRows.FindControl("rdbtn1");
RadioButton rbt2 = (RadioButton)grdRows.FindControl("rdbtn2");
RadioButton rbt3 = (RadioButton)grdRows.FindControl("rdbtn3");
RadioButton rbt4 = (RadioButton)grdRows.FindControl("rdbtn4");
string Value = RadioValue(rbt1);
//Similarly you can do for all radio button
if(!string.IsNullOrEmpty(Value))
{
lblMsg.Text = nominationsBiz.SaveSuggestion(ticketNo.ToString(), qtn_no, sqtn_no, Value);
}
}
}
protected string RadioValue(RadioButton Rbtlst)
{
string Value = "";
if (Rbtlst.Checked == true)
{
Value = Rbtlst.Text;
}
return Value;
}

jquery datepicker date not binding to asp.net textbox in gridview editing/updating (with masterpage)

in the code below, the string sFoodFormReceived1 always gets the value of DateTime.Now. I dont know how to make the date clicked on the datepicker UI bind to the textbox in the gridview gvReservationsWithForms.
protected void gvReservationsWithForms_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvReservationsWithForms.Rows[e.RowIndex];
string sFoodFormReceived1 = ((TextBox)(row.Cells[9].Controls[1])).Text;
DataTable dt = dsReservationsToBind.Tables[0];
dt.Rows[gvReservationsWithForms.EditIndex]["FoodFormReceived"] = new DateTime(System.DateTime.Parse(sFoodFormReceived1));
DataRow dr = dt.Rows[row.DataItemIndex];
var Reservation = new reservation_RoomReservationTableAdapter();
Reservation.Update(dr);
gvReservationsWithForms.EditIndex = -1;
gvReservationsWithForms.DataBind();
}
<asp:Content ID="Content4" ContentPlaceHolderID="Main" Runat="Server">
<script type="text/javascript">
$(document).ready(function ()
{$("input[id$='tbFoodFormReceivedEditItemTemplate']").datepicker();})
</script>
<asp:GridView ID="gvReservationsWithForms" runat="server"
AutoGenerateColumns="False"
DataKeyNames="RoomReservationID" AutoGenerateSelectButton="True"
allowsorting ="True" AutoGenerateEditButton="True" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" onsorting="gvReservationsWithForms_Sorting1"
onrowcancelingedit="gvReservationsWithForms_RowCancelingEdit"
onrowediting="gvReservationsWithForms_RowEditing"
onrowupdating="gvReservationsWithForms_RowUpdating"
onselectedindexchanged="gvReservationsWithForms_SelectedIndexChanged1"
onrowupdated="gvReservationsWithForms_RowUpdated">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<columns>
<asp:BoundField DataField="RoomReservationID" HeaderText="Confirmation ID" SortExpression="RoomReservationID" Visible="false" />
<asp:BoundField DataField="Room" HeaderText="Room" SortExpression="Room" ReadOnly="true"/>
<asp:BoundField DataField="BeginDate" HeaderText="Event Begin Date" SortExpression="BeginDate" ReadOnly="true"/>
<asp:BoundField DataField="EndDate" HeaderText="Event End Date" SortExpression="EndDate" ReadOnly="true"/>
<asp:BoundField DataField="BeginTime" HeaderText="Event Begin Time" SortExpression="BeginTime" ReadOnly="true"/>
<asp:BoundField DataField="EndTime" HeaderText="Event End Time" SortExpression="EndTime" ReadOnly="true"/>
<asp:BoundField DataField="Department" HeaderText="Department/Organization" SortExpression="Department" ReadOnly="true"/>
<asp:BoundField DataField="Activity" HeaderText="Activity" SortExpression="Activity" ReadOnly="true"/>
<asp:TemplateField HeaderText="Food Form Received"
SortExpression="FoodFormReceived">
<EditItemTemplate>
<asp:TextBox ID="tbFoodFormReceivedEditItemTemplate" runat="server" CssClass="datepickers"
Text='<%# DateTime.Now%>'> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FoodFormReceived") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
</asp:Content>
You may want to instead set the textbox to datetime.now in code, on RowEditing instead. That way, the binding doesn't interfere. It could be that...
also, you may get better performance if you do:
$("#<%= gvReservationsWithForms.ClientID %>")
.find("input[id$='tbFoodFormReceivedEditItemTemplate']").datepicker();
Instead, so you restrict the input controls to just the gridview, and not the entire page.

Categories